Tis Gorila
Tis Gorila

Reputation: 41

How to start function in activity A after activity B finished?

my app has 2 activities. The main activity is A. I call start B in A. (In B when user press Backbutton B's process will be killed by this code)

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);

my question is, how do I start a function in A when B is finished?

Upvotes: 1

Views: 4193

Answers (2)

Last Warrior
Last Warrior

Reputation: 1307

Start your activity B by Activity A

Intent intent = new Intent(ActivityA.this,ActivityB.Class);
startActivityForResult(intent,0);

finish your activity B with

Intent intent = new Intent();
setResult(RESULT_OK,intent );       
finish();

now in ActivityA

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data)
  {
    super.onActivityResult(requestCode, resultCode, data);
    //Do your work here in ActivityA

  }

Upvotes: 7

Aerrow
Aerrow

Reputation: 12134

Instead of this int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid); just use finish();. THis will help you to come back to the previous activity. As per your code, the application was completely killed.

Upvotes: 0

Related Questions