I have an app with a single activity in it. I need to display a branding/splash screen whenever my app is started from it's icon. My client is extremely emphatic about t开发者_StackOverflowhis, there must always be a splash screen when starting up the app. (note that there is a legal notice on it as well, so apparently the lawyers are involved in this decision)
Of course the splash screen should not show up when the orientation changes, or when coming back to the app after, say, making a phone call (the app can launch the phone dialer, BTW).
I know that the app ins't always really "starting" when it comes up, as it may have been running recently and the activity kept alive. However my client doesn't care about this technicality, to them if you start it from an icon you are "starting" the app and it must show the splash screen.
Any good strategies for this? I don't know how to tell the difference between the various ways the activity could be initiated.
Create an activity that will show the splash screen, give it the intent filter to be started when clicking on the launcher:
<activity android:name="ShowMySplashScreen" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
After showing the screen for how many seconds, call finish()
on the activity and start the actual app process.
You should tell your client that this is a REALLY bad idea. However if you really need to hack this up you none of the suggestions above will work. The only thing I can think of is to save a timestamp in a preference each time any activity pauses (onPause) and then whenever any activity resumes (onResume) check that value and if it is too long ago redirect to a splash screen activity. However this would be HORRIBLE.
Suggest to the client to create a standard splash screen with a dialog that say something along the lines of "yeah.. i have seen this.." and click to continue. When they press click you have confirmation that you never need to display the splash again...
as far as I understood your problem I suppose you need to work with onStart () and onResume ()
(for displaying splash while returning to Activity after pressing HOME
)
Regarding the splash view I would suggest use a ImageView
(if you want to show a image as splash) and set its visibility to GONE
& then when your Actvity resumes or starts make the imageview display FILL_PARENT
& (I suppose) you are done!
Take a look at this
It is created before any activities. You can set some sort of just_started flag there, check it in onCreate()
method of you activity and act accordingly.
to help you with how the activity is initiated, i found following picture from the developers guide:
as you can see, you would want to overwrite the onReseume()
function to display the intent/activity that is the splash screen
for example:
public void onResume()
{
startActivity(new Intent(this, SplashScreen.class));
}
where SplashScreen is a class that extends Activity
then as Zarah said:
After showing the screen for how many seconds, call
finish()
on the activity and start the actual app process.
or do something of the sort. have them press the screen too :P
精彩评论