Reputation: 837
How to replace or restart activity with singleinstance from another activity.
i have two activity, ActivityA and ActivityB.
in manifest:
<activity
android:name=".ActivityA"
android:label="@string/activityA"
android:launchMode="singleInstance" >
</activity>
<activity
android:name=".ActivityB"
android:label="@string/activityB" />
My question, how to restart ActivityA from method in ActivityB. Mycode no in ActivityB is:
class ActivityB extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button rButton = (Button) findViewById(R.id.restart);
rButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
restartActivityA();
}
});
}
public void restartActivityA() {
Intent intent = new Intent(this, ActivityA.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
this.finish();
}
}
If i click the button, so not restart.
Thanks.
Upvotes: 1
Views: 2506
Reputation: 13415
Try to add this to your ActivityA
:
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
}
EDIT:
Call ActivityB like this :
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
finish();
Thanks.
Upvotes: 2
Reputation: 3417
try this may be it will help.
Intent intent = getActivity().getIntent();//it will return the intent for current activity
hope this helps.
Upvotes: 0