Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - finishing activity from another activity

Tags:

android

is there 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

like image 477
Waypoint Avatar asked Dec 05 '22 22:12

Waypoint


2 Answers

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();
  }
like image 58
Thane Anthem Avatar answered Jan 01 '23 05:01

Thane Anthem


very helpful code

classname.static object.finish();
like image 29
Belal Badr Avatar answered Jan 01 '23 06:01

Belal Badr