Bala Raja
Bala Raja

Reputation: 627

Android close current activity and return to previous activity

In my second activity, I can uninstall an app after uninstall finished, the second activity remains. But I need to go for previous activity after uninstall finished

Uri packageURI = Uri.parse("package:"+packageInfo.packageName);
            Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
            startActivity(uninstallIntent);

Upvotes: 0

Views: 1259

Answers (1)

PEHLAJ
PEHLAJ

Reputation: 10136

Update your first activity (FirstActivity.java)

FirstActivity.java

  1. Use startActivityForResult(uninstallIntent, 1); //1 is REQUEST_CODE

  2. After unintalling app, FirstActivity.onActivityResult will be automatically called, you can use this method to do something.

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
            // un-installed successfully
            finish();
        }
        else {
            // failed to un-install
        }
      }
    }
    

Upvotes: 4

Related Questions