is ther开发者_开发百科e any way, how to finish certain activity from a stack? I have service, which looks for updates, and when update is found, it opens update activity, where prompt for installation will appears. But after the installation appears I want to finish update activity, because it is not necessary to still be on a stack.
Thanks
If the update activity is launching another installation activity, then you may want to override void onActivityResult(int requestCode, int resultCode, Intent intent)
in the update activity, providing the following implementation. Also, when the update activity launches the installation activity, it should do so with startActivityForResult(Intent, int)
, not with startActivity(Intent)
.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
super.onActivityResult(requestCode, resultCode, intent);
finish();
}
very helpful code
classname.static object.finish();
Try this please.
In first activity, define this before onCreate.
static TabsViewPagerFragmentActivity activityMain;
Then, in onCreate of first activity, write this.
activityMain = this;
Then, in second activity, write this when you want finish first one.
TabsViewPagerFragmentActivity.activityMain.finish();
This will destroy first activity and when you press back on second activity, you will go back to home directly.
Use finish() method of the activity class to finish certain activity
this.finish(); // you can also use the application context instead of this
Hope this will help you.
But after the installation appears I want to finish update activity, because it is not necessary to still be on a stack.
When your "update activity" calls startActivity()
to bring up "the installation", have it immediately call finish()
on itself.
精彩评论