Call Main Activity using an Intent
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 Int开发者_JAVA百科ent(this,ImageSelection.class);
switch(v.getId()) {
case R.id.button1:
startActivity(intent);
}
}
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);
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);
}
});
精彩评论