How to achieve the following flow in android app?

My app receives a push notification and one of its activity gets launched. Now,

  • Press home
  • Relaunch app from home screen(app launched with main activity)
  • Press back
  • eg Activities A-->B--->C

  • Notification launches 'C'
  • Press HOME on C
  • Relaunch app ('A' gets launched)
  • Press back
  • Now the weirdness appears, pressing back is taking the user to same activity that was launched on notification click, in this case its taking the user to 'C'

    I do not want this flow..pressing back key on main activity should exit the app.

    any help?


    Override the back button to do your desired function:

        @Override
    public void onBackPressed() {
        Your function here.
        super.onBackPressed();
    }
    

    And also you can add flags to your intent while calling respective activiies:

     1.FLAG_ACTIVITY_NO_HISTORY
    

    用这个-

     @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {      
        if ((keyCode == KeyEvent.KEYCODE_BACK))
        {
    
        finish();//do ur task
        }
        //same check for home screen key and do u task
    
        return super.onKeyDown(keyCode, event);
        }
    
    链接地址: http://www.djcxy.com/p/26170.html

    上一篇: 从前台引回活动

    下一篇: 如何在Android应用程序中实现以下流程?