tags:

views:

175

answers:

4

I wish to have one application that runs in the background, which knows when any of the built-in applications (messaging, contacts, etc) is running.

So my questions are:

  1. How I should run my application in the background.

  2. How my background application can know what the application currently running in the foreground is.

Responses from folks with experience would be greatly appreciated.

-- Dhaiwat Bhavsar([email protected]).

+2  A: 

The ActivityManager class is the appropriate tool to see which processes are running.

To run in the background, you typically want to use a Service.

Charles Duffy
A: 

I have one application in background that wants to be pop-up(in foreground) when user go to messaging app and select Delete Message.

this stuff i want to do,if you have any suggestion than please let me know.

dhaiwat
A: 

Do something like this:

int showLimit = 20;

/* Get all Tasks available (with limit set). */
ActivityManager mgr = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> allTasks = mgr.getRunningTasks(showLimit);
/* Loop through all tasks returned. */
for (ActivityManager.RunningTaskInfo aTask : allTasks) 
{                  
    Log.i("MyApp", "Task: " + aTask.baseActivity.getClassName()); 
    if (aTask.baseActivity.getClassName().equals("com.android.email.activity.MessageList")) 
        running=true;
}
ChristianS
A: 

Hi even am trying to do the same....could someone please help me? I have one application running in the background(broadcast receiver)...this receiver should detect what application came into foreground by the user and be able to retrieve the package name of that foreground application. As of now the receiver is able to get the package name but how will it detect when an application comes to foreground...

please help someone....i have searched is most of the forums and i don't get a positive response:(

thanks alot

suppi