Reputation: 38960
Is it possible to recall the main activity from another activity using an intent? I tried running the code below (the main Activity is ImageSelection):
public void onClick(View v) {
Intent intent = new Intent(this,ImageSelection.class);
switch(v.getId()) {
case R.id.button1:
startActivity(intent);
}
}
Upvotes: 0
Views: 2944
Reputation: 2492
Try using this code instead of your onClick()
class:
Button btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), ImageSelection.class);
startActivity(i);
}
});
Upvotes: 0
Reputation: 44919
Yes, that is the correct way to start the ImageSelection
activity.
If you'd like to bring a previous ImageSelection
to the front or clear the Activities on top of it, try one of the Intent flags:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
or:
intent.setFLAGS(Intent.FLAG_ACTIVITY_BRING_TO_FRONT);
Upvotes: 2