Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this questionI'm a new with Android. I want to make an applic开发者_运维百科ation that always running. User can't switch to other application, if my app is exited then it will be launched automatically.
You can achieve this with intent filters in your manifest, on your activity.
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
This makes your activity an alternative for the home-app, but the user needs to select your app as the default app the first time it's run. There is no other way.
After the user selects your app as the default home app it will be launched every time 'home' is pressed. You can then capture the other buttons as usual and do whatever you want (e.g. nothing when 'back' is pressed).
into AndsroidManifest insert this:
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
精彩评论