У меня есть приложение, которое начинается с анимации, а затем мы переходим к другому (P1). Но если я нажму кнопку «Назад» из p1, я вернусь к анимации (LoadActivity), и если я сейчас нажму кнопку «Назад», тогда я должен перейти к диспетчеру приложений, но вместо этого вернусь к активности P1, так как есть цикл от p1 до LoadActivity и от LoadActivity к P1BackButton не работает должным образом
LoadActivity.java
public class LoadActivity extends Activity {
boolean doubleBackToExitPressedOnce=false;
ImageView im;
Animation rotate;
private Handler mHandler;
private Runnable mRunnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.load);
im = (ImageView) findViewById(R.id.load_icon);
rotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.load_page);
rotate.setInterpolator(new LinearInterpolator());
im.startAnimation(rotate);
mHandler = new Handler();
mRunnable = new Runnable() {
@Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
P1.class);
startActivity(nextPageIntent);
}
};
mHandler.postDelayed(mRunnable, 3000);
}
public void onBackPressed() {
Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();
mHandler.removeCallbacksAndMessages(mRunnable);
android.os.Process.killProcess(android.os.Process.myPid());
}
P1.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.p1);
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
context=this;
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.lay_inflate_land,null);
RelativeLayout f=(RelativeLayout)findViewById(R.id.iv_p1);
f.addView(view);
}
else {
context=this;
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.lay_inflate,null);
RelativeLayout f=(RelativeLayout)findViewById(R.id.iv_p1);
f.addView(view);
}
button = (Button)findViewById(R.id.let_start_p2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent nextPageIntent = new Intent(getApplicationContext(), P2.class);
startActivity(nextPageIntent);
}
});
}
@Override
public void onBackPressed() {
Intent nextPageIntent = new Intent(getApplicationContext(), LoadActivity.class);
startActivity(nextPageIntent);
}
попытайтесь завершить свою деятельность в onBackPressed() после вызова LoadActivity. –