Android デバイスに表示されているアクティビティを知りたい
検索するアクティビティの場合はコードを実行しますそうでない場合は別のコードを実行します
目的は、このタスクをチェックするための Android サービスを作成することです
Android デバイスに表示されているアクティビティを知りたい
検索するアクティビティの場合はコードを実行しますそうでない場合は別のコードを実行します
目的は、このタスクをチェックするための Android サービスを作成することです
This should work for you:
Get active Application name in Android
Just tweak it with the functionality you want, and you should be able to check rather easily.
Are you sure that's what you want?
purpose is to make an android service to check this task
If you told us what was the reason behind your "purpose", I'm almost sure we could help you with a better way of doing what you want (probably we could find a way which would waste less battery and which would antagonize less your users).
In any case, here is the answer to your question:
Use getRunningTasks of ActivityManager to get a list of the recently launched activities.
public List getRunningTasks (int maxNum)
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that "running" does not mean any of the task's code is currently loaded or activity -- the task may have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.
You might also want to use the flag RECENT_WITH_EXCLUDED
to make sure you get all the activities, even the ones that purposefully exclude themselves from that list.
public static final int
RECENT_WITH_EXCLUDED
Added in API level 1 Flag for use with
getRecentTasks(int, int)
: return all tasks, even those that have set theirFLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
flag.