Pergunta

I have implemented GCM in 5 of my apps still I have a doubt about the running of GCM in background cause of apps behavior, may be am little confused about apps foreground and background running styles. I see my apps listed under "Downloaded" section of the Application in Settings when they get installed and registered the device id and I press the back key in my app.

They don't get listed under "Running" section. They come to "Running" section when there is a message (notification) and when the notification is generated and shown in notification bar they get cleared off from "Running". However if I click on "Downloaded" section, I see a "Force Stop" button activated (which I see for most of the apps) that means something is running.

My question is that is my app running and taking resource of cell phone while there are no activity open if I am using GCM in my app? Is there a service running in background if yes they why it is not listed with all other apps in "Running"?

Foi útil?

Solução

Force Stopping an app doesn't mean that it was running before you force stopped it. It's just a way to let the user tell Android they don't want the app to be started again, until the user launches it again manually.

If you force stop an application, it won't be able to receive GCM messages until the user manually launches it again, because the GCM background service won't be able to launch it automatically.

This behavior was introduced in Android 3.1 with Launch Controls:

Launch controls on stopped applications

Starting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state and provides a means of controlling their launch from background processes and other applications.

Note that an application's stopped state is not the same as an Activity's stopped state. The system manages those two stopped states separately.

The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application.

FLAG_INCLUDE_STOPPED_PACKAGES — Include intent filters of stopped applications in the list of potential targets to resolve against.

FLAG_EXCLUDE_STOPPED_PACKAGES — Exclude intent filters of stopped applications from the list >of potential targets.

When neither or both of these flags is defined in an intent, the default behavior is to include filters of stopped applications in the list of potential targets.

Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications. A background service or application can override this behavior by adding the FLAG_INCLUDE_STOPPED_PACKAGES flag to broadcast intents that should be allowed to activate stopped applications.

Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications).

GCM has a process running in the background, but it's a process that serves all the applkication on the device, so installing additional apps that use GCM has no effect on the number of background processes running.

Outras dicas

Its like asking if the Calling App or the Message app always keep running, waiting for a phone or an SMS. Well, there are Android Framework Components called BroadCastReceivers. The OS Broadcasts an Intent message whenever a call is received, message is received, Low Battrey is detected, An Alarm is Fired and even when an Notification is received.

Then we have various applications which are registered to receive some Broadcast messages that the OS fires. This is done in the apps Manifest (generally). So if your app is registered to receive a Broadcast message for GCM message, your app will receive it.

Just remove the broadcast receiver for GCM in your Manifest. Your app will no longer respond to a GCM. Next how does the app distinguish between multiple GCM receivers on a single Device? I mean how to distinguish if the notification GCM is for app A or app B?

This has to do with the APP_ID with which you register with GCM. That can be mapped to your App's Package name. We provide package name when we register for GCM

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top