0

I am new to android.

I am developing one app.

Based on that when my application will start,a back ground service will start.

And it run background and notifi the user,when user starts new activity.

For example user opens the camera,contacts..through the background service i want to get every time which activity is opened.

If any one has the solution,please help me

Thanks in advance.

kiran
  • 3,244
  • 7
  • 34
  • 57

2 Answers2

2

this code will return All packages that have been loaded into the process .

see the results after lauching related apps and make changes .

    private String[] AppForground() {

            ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            List<RunningAppProcessInfo> l = mActivityManager
                    .getRunningAppProcesses();
            Iterator<RunningAppProcessInfo> i = l.iterator();
            while (i.hasNext()) {
                RunningAppProcessInfo info = i.next();
                if (info.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    return info.pkgList;
                }
            }

            return null;
}
}
Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
1

you can achieve this scenario using following steps. This is my view for solution.

  • make setter()/getter() method for activity name.

  • whenever you change your activity set that activity's name using set method.

  • now using getter() method you can see which is currently running activity.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
  • hey Kiran , Please accept the answer if it was useful for you, so that it can be useful for others. – Lucifer Jan 25 '12 at 13:23
  • StackOverflow is not an advertising site. So please stop advertising your answers and let the asker do what he like and choose the answer he found most useful – Adel Boutros Jan 25 '12 at 13:30
  • seems you did not read question properly . he want which among other app is in foreground ( For example user opens the camera,contacts) . – Shailendra Singh Rajawat Jan 25 '12 at 13:49