1

I am facing this issue:

  • Create intent from an Activity
  • Then at Home screen, I call startActivity with this intent
  • After I startActivity with intent A then intent B, the intent A still remain behind

I want:

  • free intent A when I startActivity with intent B
  • press BACK from any intents will back to Home screen

Please help me.

tvAbout = (TextView) mSettingsMenu.findViewById(R.id.tv_about);
tvAbout.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(v.getContext(), AboutActivity.class);
        activity.startActivity(intent);
        mDrawerLayout.closeDrawer(Gravity.LEFT);
    }
});
tvProfile = (TextView) mSettingsMenu.findViewById(R.id.tv_profile);
tvProfile.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(v.getContext(), ProfileActivity.class);
        activity.startActivity(intent);
        mDrawerLayout.closeDrawer(Gravity.LEFT);
    }
});
...
Trung NT Nguyen
  • 403
  • 2
  • 14

2 Answers2

0

The second time you start a Activity, the intent is received in a method called onNewIntent. You can set the intent for the activity at this time.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
}
jDur
  • 1,481
  • 9
  • 10
0

try this in your code

A--->>> to B Activty (Here A finished when B Activity is opened)

 Intent addIntent = new Intent(this, B_AboutActivity.class);
                  startActivity(addIntent);
                  finish();

Then press Back button open the A Activty finish the B activity

@Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK)) {

            Intent intent = new Intent(getApplicationContext(),A_Activty.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra("EXIT", true);
                startActivity(intent);
                finish();


            }
            return super.onKeyDown(keyCode, event);
        }
Android Dev
  • 421
  • 8
  • 26