How to restart activity with singleInstance activity from other activity


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.



Try to add this to your ActivityA :

@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); }


Call ActivityB like this :

Intent intent = new Intent(this, ActivityB.class); startActivity(intent); finish();



try this may be it will help.

Intent intent = getActivity().getIntent();//it will return the intent for current activity

hope this helps.


  • How to find the closest date from array to push into already chosen dates array
  • Hibernate session in threads
  • Play services version issue for SMS Retriever Api
  • WCF VSTO client cannot find default endpoint when deployed on win2k8
  • Problems with connecting bluetooth SPP in android?
  • Parse and upload a csv file in D3.js V5
  • How can I have a toolbar stay at top of screen instead of showing up on the whole screen?
  • How to get spesific error instead of Internal Service Error
  • Disable tapping on group header in LongListSelector
  • How to find DWARF_DSYM_FOLDER_PATH and DWARF_DSYM_FILE_NAME in xcode 9.3
  • Oracle outer join with filter condition on the second table
  • Java Regex Finding digits in a String
  • Connect SQL Server on button click VB.net
  • OSGi console not shown in command line
  • cq5 accessing osgi servlet through Url
  • Get All the instance subclass of trait using Google Guice
  • Post-receive hook to pull from bare repo
  • Having a custom repository with DBAL connection in Symfony 2 / Doctrine 2?
  • Using VCL Styles gives a exception / crash in TOpenDialog
  • how to change the black color to Red with opencv python
  • How do I link when building with llvm libraries?
  • List using with references, changes behavior when used as a member
  • Display variable as html in Google App Script?
  • watir webdriver - window not found
  • How to debug iBeacons and Passbook
  • Populating a database table with returned JSON
  • How to use AJAX to upload large CSV file? [closed]
  • Multiplying polynomials/simplifying like terms
  • Typeahead.js does give me suggestions but doesn't select them
  • Floating parent div grows to hypothetical width of floating child div
  • How to integrate angular2-material (alpha 8.2) with angular2-Quickstart app
  • Send array to next viewcontroller iOs xcode [duplicate]
  • Codeigniniter insert data through models and controller
  • Android Library Projects on Windows and Mac
  • PHP Permalinks.. how to change?
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?