That's my first question and I'm an Android noob yet (hopefully), so please try to forgive me if I'm asking stupid questions.
I'm working on an Android application and I have to make a splash screen. I made one using this answer: How do I make a splash screen? . It is working very fine, but... this solution makes another big thread for the rest of application and I am trying to avoid that - I think it slows whole application (another app thread). Am I right?
I tried to invert whole process - I'm invoking MainMenu activity, then making another thread just for splash:
public class MainMenu extends Activity implements OnItemClickListener {
private GridView gridView;
private AlertDialog.Builder dialog;
private Intent intent;
private ApplicationPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
prefs = new ApplicationPreferences(this);
setTheme(prefs.GetApplitacionTheme());
SQLDatabase.onCreate();
if (prefs.SplashScreenEnabled()) {
new Runnable() {
@Override
public void run() {
startActivity(new Intent(MainMenu.this, SplashScreen.class));
}
}.run();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
gridView = (GridView)findViewById(R.id.gridView);
gridView.setAdapter(new AdapterMainMenu(this));
gridView.setOnItemClickListener(this);
}
Then in my SplashScreen activity:
public class SplashScreen extends Activity {
private Locale locale;
private Configuration config;
private ApplicationPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
}
@Override
protected void onResume() {
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finish();
}
After onCreate() Android calls onResume() so I decided to pause thread here and after that finish activity.
When application comes back to the main thread it crashes and I don't know why. What am I doing wrong?
Thanks in advance! Unguis