开发者

android splash screen

i have a program that shows a splash screen.But the problem is whenever i refresh same page again it appears.Is there any method to st开发者_StackOverflowop splash screen again and again.I want it just comes at first time not again and again. Thank you


So you basically want the splash screen appear once per app launch. Here's a quick and dirty way:

  1. Subclass android.app.Application as, say, MyApp;
  2. Declare that class in AndroidManifest.xml (<application android:name=".MyApp" ... >) so that it would get instantiated at app launch time;
  3. Give it a public static boolean SPLASH_SHOWN = false;
  4. Now, in your Activity's onCreate() check if SPLASH_SHOWN = false, show splash and set it to true.


If you implement the splash screen in the same activity with another view layout (the main layout) - for example, display splash screen first, then swich the view to the main layout - I suggest to control the content view setting in onResume(). Use a boolean variable (displayedSplash) to remember whether the splash screen has been displayed. If it has not been displayed (start the activity the first time, displayedSplash == false), then set the view to the splash screen, after that switch to the main layout and set displayedSplash = true. If it has been displayed (refresh the page, displayedSplash == true), just set the view to the main layout.

Another simple and safe solution for simple splash screen is implementing it as an activity, then start the main activity. When the onResume() is called the second time, just finish the activity. Please refer to this Wiki for the detail.


Most of the times I call finish() method inside onPause() method in splash activity. This will work fine for me

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜