0

My application has a splash screen as its Launcher activity, and I have an option in the Shared Preferences to go straight to the Main Activity, so I needed a way to programmatically select the Launcher activity.

I initially tried using another activity that launches before the splash screen, and performs the logic that opens the next activity, as suggested here Programmatically change launcher activity but I found that the screen flickered during activity transitions even with android:noHistory="true" declared in the manifest.

Instead I added the same simple logic used in the activity mentioned above to my original splash screen activity, which sets the screen content based on the shared preferences. I use a handler and a postDelayed timer which dictates how long the splash screen is displayed and as an experiment I set the postDelayed time quite low, 100 ms, and there is no obvious screen flickering during the transition to the Main Activity. Why is this so?

Community
  • 1
  • 1

2 Answers2

0

You're doing something wrong. You don't need to use Delay!

Just use:

String MAIN_FLAG = "Your Flag here";

SharedPreferences prefs = this.getSharedPreferences(
      "com.example.app", Context.MODE_PRIVATE);
//Saving Data
prefs.edit().putString(MAIN_FLAG , "FLAG";
//Load Data (Second parameters is default value)
prefs.getString(MAIN_FLAG , "");

And Than in Your Splash:

if (this.getSharedPreferences("com.example.app", Context.MODE_PRIVATE)
           .getString(MAIN_FLAG , "") != "") 
   loadFirstAcivity();
else 
   loadSecondActivity();
GensaGames
  • 5,538
  • 4
  • 24
  • 53
  • Thanks, this is basically what I've got. I added the delay in an attempt to smooth over the transition between the activities, otherwise it seems quite jarring. Is there a way to reduce/remove that? – Michael M-H Nov 11 '15 at 14:32
  • @MichaelM-H I can not fully understand. If not suitable transition between activities, but they should be strictly specified immediately. animation. You can look on the Internet examples of animation when switching screens. If I understand the problem. – GensaGames Nov 11 '15 at 22:29
0

You can try using Activity.overridePendingTransition() with 0 as animation ID to show a smooth transaction. For example :

    overridePendingTransition(0, R.anim.anim_zoom_out);
Amud
  • 1