2014-08-28 64 views
0

我的应用程序以动画开头,然后移动到另一个(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); 
     } 
+0

尝试调用LoadActivity完成后,在onBackPressed()的活动。 – 2014-08-28 04:46:32

回答

0

尝试更换验证码:

@Override 
public void onBackPressed() { 
    Intent nextPageIntent = new Intent(getApplicationContext(), LoadActivity.class); 
    startActivity(nextPageIntent); 
    finish(); 
} 
+0

这有助于但现在,当我在P1按后退按钮,然后谈到LosdActivity但现在,如果我再次按下返回键再次重新启动Loadactivity,现在我按后退按钮则退出 – 2014-08-28 04:54:15

+0

所以我需要按backkbutton两次退出 – 2014-08-28 04:54:36

+0

试对此,http://stackoverflow.com/questions/8430805/android-clicking-twice-the-back-button-to-exit-activity – SathishKumar 2014-08-28 04:58:31