i have application which starts with an animation and then we move to another(P1 )activity. But if i press back button from from p1 then i go back to the animation(LoadActivity) and if i press back button now then i should go to application manager but instead i go back to P1 activity like there is a loop from p1 to LoadActivity and from LoadActivity to 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);
}