Answer the question
In order to leave comments, you need to log in
Does a blank "page" appear between activities when you press back?
There are three activities. HomeActivity is the main one. OneActivity and TwoActivity
The application loaded, I moved from the main activity (HomeActivity) to another (for example, OneActivity), when returning back, an empty page appears between the activities (OneActivity and HomeActivity), i.e. It turns out that in order to return from the activity (OneActivity) to the main activity (HomeActivity) you have to press it twice back.
In OneActivity and TwoActivity, as you can see, fragments are called through them.
HomeActivity
package com.example.frag4;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class HomeActivity<onClick> extends AppCompatActivity implements View.OnClickListener {
Button btnfagtaho;
Button btnmain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
btnfagtaho = (Button) findViewById(R.id.btnfagtaho);
btnmain = (Button) findViewById(R.id.btnmain);
btnfagtaho.setOnClickListener(this);
btnmain.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent;
switch (v.getId()) {
case R.id.btnfagtaho:
intent = new Intent(this, OneActivity.class);
startActivity(intent);
break;
case R.id.btnmain:
intent = new Intent(this, TwoActivity.class);
startActivity(intent);
break;
}
}
}
package com.example.frag4;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class OneActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
getSupportFragmentManager().beginTransaction().replace(R.id.mainfagtaho, new Fagtaho1()).addToBackStack(null).commit();
}
}
package com.example.frag4;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class TwoActivityextends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
getSupportFragmentManager().beginTransaction().replace(R.id.main, new Fragment1()).addToBackStack(null).commit();
}
}
Answer the question
In order to leave comments, you need to log in
getSupportFragmentManager().beginTransaction().replace(R.id.mainfagtaho, new Fagtaho1()). addToBackStack (null).commit();
It is better not to use methods whose purpose you do not understand. First, the transaction is removed from the stack, then there is a transition between activities. Remove it and you'll be ok.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question