我有一个以动画开头的应用程序,然后我们转移到另一个(P1)活动。 但是,如果我从p1按回按钮然后我回到动画(LoadActivity),如果我现在按回按钮然后我应该去应用程序管理器,但我会回到P1活动,就像从p1到LoadActivity的循环从LoadActivity到P1
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);
}
答案 0 :(得分:0)
尝试替换此代码:
@Override
public void onBackPressed() {
Intent nextPageIntent = new Intent(getApplicationContext(), LoadActivity.class);
startActivity(nextPageIntent);
finish();
}