0

I am opening splash activity once, this is what i have done.

public class StartupActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SharedPreferences settings = PreferenceManager
                .getDefaultSharedPreferences(StartupActivity.this);
        String lang = settings.getString("opened", "");
        if(opened.equals("1")
        {
        Intent i = new Intent(getApplicationContext(), SecondActivity.class);
        startActivity(i);
        finish();
        }else { //I am setting here  opened to 1 
        setContentView(R.layout.activity_main);} 
}

Where does the problem lie? When I open the app first time, this activity shows setcontentview activity main, but second time user opens app it goes to secondactivity .But the problem is , for couple of milliseconds the second time i open the app it is making it obvious that splash activity is opening then closing for couple of milliseconds.

user3278732
  • 1,694
  • 10
  • 31
  • 67
  • After you opened the splash activity You didn't set the value as 1. `putString` – Viswanath Lekshmanan Mar 24 '16 at 04:43
  • i have done that, thats not the issue at all. – user3278732 Mar 24 '16 at 04:45
  • You're launching the `Activity`; that's why it's showing. The `Activity`'s window is still going to load, even if you don't call `setContentView()`. – Mike M. Mar 24 '16 at 04:46
  • yes, how can i solve that thing? – user3278732 Mar 24 '16 at 04:47
  • Your screen will splash at anycost. Because it is the launcher activity in your application. Try to call super after checking prefereences . May reduce a millisecond. Note: In slower devices your application will show a black screen for some seconds – Viswanath Lekshmanan Mar 24 '16 at 04:48
  • Where do you save "opened" parameter of preferences? – Vyacheslav Mar 24 '16 at 04:49
  • in the commented part, /I am setting here opened to 1 . – user3278732 Mar 24 '16 at 04:50
  • You could create an `Activity` with a `NoDisplay` theme as the launch `Activity`, and decide in its `onCreate()` whether to start `StartupActivity` or `SecondActivity`. – Mike M. Mar 24 '16 at 04:50
  • @user3278732 even though you mentioned that you set value for "opened" but there is still high chance that you missed something there. can you put code for it. I just want to make sure you use apply() or commit() – Vilen Mar 24 '16 at 05:39

1 Answers1

0

I believe your splash is the launcher activity of your application and what you are trying to do is , once you have launched the splash and passed the value to second activity then splash shouldn't show . I saw a similar question long ago , check if it answers it

App restarts rather than resumes

Community
  • 1
  • 1
VarunJoshi129
  • 4,802
  • 1
  • 12
  • 10