Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <service
  2. android:name="com.myapp.MyService"
  3. android:stopWithTask="true" />
  4.  
  5. <service
  6. android:name="com.myapp.MyService"
  7. android:stopWithTask="false" />
  8.  
  9. public void onTaskRemoved(Intent rootIntent) {
  10.  
  11. //unregister listeners
  12. //do any other cleanup if required
  13.  
  14. //stop service
  15. stopSelf();
  16. }
  17.  
  18. int previousProcessID = mSharedPreferencesUtils.getInt(SharedPreferencesUtils.APP_PROCESS_ID);
  19.  
  20. int currentProcessID = android.os.Process.myPid();
  21.  
  22. if ((previousProcessID == currentProcessID)) {
  23. // This ensures application not killed yet either by clearing recent or anyway
  24. } else {
  25. // This ensures application killed either by clearing recent or by anyother means
  26. }
  27.  
  28. public class OnClearFromRecentService extends Service {
  29.  
  30. @Override
  31. public IBinder onBind(Intent intent) {
  32. return null;
  33. }
  34.  
  35. @Override
  36. public int onStartCommand(Intent intent, int flags, int startId) {
  37. Log.d("ClearFromRecentService", "Service Started");
  38. return START_NOT_STICKY;
  39. }
  40.  
  41. @Override
  42. public void onDestroy() {
  43. super.onDestroy();
  44. Log.d("ClearFromRecentService", "Service Destroyed");
  45. }
  46.  
  47. @Override
  48. public void onTaskRemoved(Intent rootIntent) {
  49. Log.e("ClearFromRecentService", "END");
  50. //Code here
  51. stopSelf();
  52. }
  53.  
  54. <service android:name="com.example.OnClearFromRecentService" android:stopWithTask="false" />
  55.  
  56. startService(new Intent(getBaseContext(), OnClearFromRecentService.class));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement