Override the onDestroy
method of MainActivity
in that set a public
static
Boolean
field of MainActivity
. In that method set that public
static
field as true
. Check for its value in EventActivity
before you finish it i.e. when you are coming back from EventActivity
to MainActivity
. And fire an intent to start MainActivity
from EventActivity
if it's value is true
. And set it's value as false
in onCreate
of MainActivity
.
As follows:
In MainActivity.java
public class MainActivity extends Activity {
public static boolean isMainActivityDestroyed = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isMainActivityDestroyed = false;
.
.
.//Do something here
}
@Override
protected void onDestroy() {
super.onDestroy();
isMainActivityDestroyed = true;
.
.
.//Do something here
}
}
In EventActivity.java
public class EventActivity extends Activity {
.
.
.//Some methods
//Method which finishes EventActivity & starts MainActivity if destroyed
public void buttonOnClick()
{
if(MainActivity.isMainActivityDestroyed)
{
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
finish();
}
}
}
If isMainActivityDestroyed
becomes true then it is an indication that MainActivity
used finish()
.