Is there a way for Android application to detect how it is being launched? whether by a BOOT or by user launching the application from the application list?
When my application is launched on boot I don't want any activity to show at all. When the user specifically launches it from the appl开发者_JAVA百科ication list, then and only then would I want the main activity to show. If I could detect whether the launch was a user launch or system boot launch I might be able to control this.
What you're looking for is the Intent that started the application. In the manifest file of your Android project you can specify which Intents will launch which Activities. The documentation page for Intent actually has a really thorough explanation of how to use this feature, with example code and everything:
http://developer.android.com/reference/android/content/Intent.html
The Intent that will be called when a user selects your application from a launcher will look like:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
If you want a different Activity to launch when the phone boots (there's an intent filter value "android.intent.action.BOOT_COMPLETED"), you just add a different IntentFilter to the Activity's tag in the manifest.
精彩评论