2014-08-28 36 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