开发者

Best practice for monitoring and killing an activity from a background service?

I'm trying to figure out the most efficient way of using ActivityManager to programmatically monitor when a package is running/executed, and then to programmatically kill it. I can do it on demand using manager.killBackgroundProcesses(processName) with 2.2, and my code works fine for that, but i'd like to register a backgrou开发者_如何转开发nd service monitor if possible.. Or some sort of an intent launching monitor for the specific package name?

What would be the most efficient and dependable way to do this?

Note: This isn't for any sort of a behind-the-scenes, malicious kill... I am calling <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /> in my manifest, so users will know exactly what the app does.


I believe the best practice would be using the AlarmManager to schedule your polling. The downside is that the AlarmManager only polls on a preset number of intervals. The smallest interval is 15 minutes. For majority of circumstances, I think this is enough.


i'd like to register a background service monitor if possible

There is no such concept in Android.

Or some sort of an intent launching monitor for the specific package name?

There is no such concept in Android.

I need it to be relatively instant.. or within seconds or so. I don't think constantly polling would be very efficient.

Then you will simply have to live with inefficiency, or don't write the app. Android is not set up to support apps like the one you are trying to write.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜