0

My app has the following Activities:

  • DashboardActivity
  • SplashActivity
  • MainActivity

This how the flow is required: The dash board has a button that starts up the MainActivity. The onCreate() method of the main activity checks if a user-profile was previously created, if yes, then it starts normally (this is fast, no GUI delay). If no user-profile is found, then it's required to display a splash screen having instructions/how-to for the mainActivity, meanwhile the onCreate() of the main activity creates a new user-profile file(slow and GUI blocking).

What I'm currently see is the splash/instructions showing delayed after the slow user-profile creation ends.

Here is a code snippet from MainActivity.

private void showUsage(){
    Thread splashTread = new Thread() {
        public void run() {
            try {
                Intent instructionIntent = new Intent(MainActivity.this,
                        InstructionsActivity.class);
                startActivity(instructionIntent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    };
    splashTread.start();
}

@Override //MainActivity
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    if (!IsProfileExists()){
        showUsage();
        try{
               createUserProfile(); //slow!
        } catch (Exception e) { }
    }

    /*Continue with MainActivity*/
  }

The Splash dismisses itself by a click:

   public class InstructionsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.instructions_layout);
    ImageView instructions = (ImageView) findViewById(R.id.ivInstructions);
    instructions.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });
}
}

The problem: The Instructions Activity (splash) shows after the GUI gets block from the MainActivity onCreate().

Any clues?

Tarek Eldeeb
  • 588
  • 2
  • 6
  • 24

1 Answers1

1

Do the condition check (IsProfileExists()) from dashBoardActivity and call the Splash activity if profile doesn't exist.

deepdroid
  • 633
  • 5
  • 26
  • I dont want this flow, because when the back-button is pressed from the main activity it will return to the splash!! I dont want the splash to re-appear again. Do you know a workaround to this? – Tarek Eldeeb Apr 24 '13 at 21:59
  • You can remove your splashActivity from the stack calling finish on Splash. So it wont showup on back key press. Something like this,instructions.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(InstructionsActivity.this, MainActivity.class); startActivity(intent); finish(); } }); – deepdroid Apr 24 '13 at 22:25
  • I didnt know that finish() removes an activity off the stack. Thanks. – Tarek Eldeeb Apr 28 '13 at 11:49