Android Forum » Android Developer Forum » Android Developer Forum » App that run in background and display alerts- how to?

App that run in background and display alerts- how to?

App that run in background and display alerts- how to?
created on Feb 2, 2013 9:51:30 PM
Hi,
I need to write app to run in background and to display massage when it arrives. So the user can use another app, but when it get massage it would display it. like GO SMS.
thanks
Reply with quote Reply Link ±0     (0 votes)
RE: App that run in background and display alerts- how to?
created on Feb 2, 2013 10:10:10 PM
The android API demos contain an example for doing this. You'll basically need to run a service and setup a notification event. The demos should be located in the folder in your android SDK:
android-sdk/samples/apidemos

Hope this helps!
Reply with quote Reply Link ±0     (0 votes)
RE: App that run in background and display alerts- how to?
created on Feb 4, 2013 9:24:34 AM
You will be able to do this starting a service,which will run at background of your Application,Even you close the application.

A service needs to be declared in the AndroidManifest.xml and the implementing class must extend the Service class or one of its subclasses. The following code shows an example for a service declaration and its implementation.

<service
android:name="MyService"
android:icon="@drawable/icon"
android:label="@string/service_name"
>
</service>
public class MyService extends Service {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//TODO do something useful
return Service.START_NOT_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
//TODO for communication return IBinder implementation
return null;
}
}
A service runs by default in the same process as the application. in its own thread.

Therefore you need to use asynchronous processing in the service to to perform resource intensive tasks in the background.
Reply with quote Reply Link ±0     (0 votes)