简体   繁体   中英

resuming activity in Android using Service

I have a mainActivity .
When starts, it starts a service and bonds it.
There is a timer which will send the mainActivity (this) to back after X seconds, while the service keep running and listening, i use moveTaskToBack (true) .
When the service listener triggered, the service starts the activity, but instead of the activity to be called through onResume() (since it was sent to back) its called through onCreate() , to call the activity currently i use :

Intent dialogIntent = new Intent(getBaseContext(), MainActivity.class);
dialogIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
getApplication().startActivity(dialogIntent);

Which explains why the activity is created all over again. I tried using FLAG_ACTIVITY_REORDER_TO_FRONT but got an exception.

add this attribute in activity of AndroidManifest.xml android:launchMode="singleInstance" in AndroidManitest.xml

AndroidMenifest.xml

 <application>
        <activity
            android:launchMode="singleInstance"> 
        </activity>
    </application>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM