Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Affichage
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline

How to force a stay in an activity, the return :)

29
March
2013

How to force a stay in an activity, the return :)

Android2EE - Expertise - Formation - Consulting Android
Hello
Still me, yet my V. Matteo trainee who have questions (in January).
Another way to achieve this is simple also, just when the activity is paused to launch a service (say StayHereActivity) and killing activity (finish).

Intent startActivitiesCops = new Intent (this, ActivtiesCopsService.class);
startService (startActivitiesCops);
super.onPause ();
Finish();

The service itself, does that restart activity:

public int onStartCommand (Intent intent, int flags, int startId) {}
Log.e ("ActivtiesCopsService", "onStratCommand");
Intent startMain = new Intent (ActivtiesCopsService.this, MainActivity.class);
startMain.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity (startMain);
stopSelf();
Return Service.START_STICKY;
}

Y' has not even need permission.
Thank you who? Thanks Android2EE:)
And don't forget the Android2EE formations to become ultimate on Android:
Comprehensive training Android

Soon, I hope.
Mathias Séguy
This email address is being protected from spambots. You need JavaScript enabled to view it.

Founder Android2EE
Training - Expertise - Consulting Android.
EBooks learn programming Android.
AndroidEvolution

You must be connected to post a comment.

Original author: MathiasSeguy
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Affichage
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline