Service check (Service) in Android system



  • Hello. Write the app. Androidwhose overall structure is the main Actvity (plus a bunch of daughters Activity Activity, but not particularly relevant to the question) and the posting class (Service). By pressing the buttons in chapters. Activity This heir of service is being launched and fulfils unspecified tasks.

    Two questions:

    (a) closed ActivityMy service continues to work independently and beyond?

    (b) if (a) = true, then from a later launch (snow) at a point of time Activity Determine whether the service works in the system or not?



  • Decision:

        ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
     List<ActivityManager.RunningServiceInfo> rs = am.getRunningServices(50);
    

    for (int i=0; i<rs.size(); i++) {
    ActivityManager.RunningServiceInfo
    rsi = rs.get(i);
    Log.i("Service", "Process " + rsi.process + " with component " + rsi.service.getClassName());
    }

    This piece of code is in mine. Activity Do what I need. In the cycle, we'll just compare the grade of service with ours and continue to do as we thought logically.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2