Getting the Forefront Activity of any application in a Service written in another application

I want that I need a link to the current activity of ANY app that is in the foreground.

Basically I wrote a service and I want to get a link to the current foreground activity in that service. With "current" I mean any application activity other than the one that started this service.

+3
android android-intent android-activity service intentservice


source to share


2 answers


I want that I need a link to the current activity of ANY app that is in the foreground.



It's impossible. Other applications run in other processes; you don't have access to Java objects like Activity

instances in these processes.

0


source to share


This code works for me:



ActivityManager manager = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);    
List<ActivityManager.RunningAppProcessInfo> tasks = manager.getRunningAppProcesses();
Log.d("App", tasks.get(0).processName);

      

0


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics