I have written a few Android apps, and have always declared a starting Activity
as the:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
It would be great for scoping some global methods, statics, shared prefs, etc if I could start my app using an Application
that then calls the first Activity
from it's onCreate()
after setting up prefs, etc, but I haven't been able to find any examples of this design pattern... when I try this in code, I get a ClassCastException
:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// do stuff (prefs, etc)
// start the initial Activity
Intent i = new Intent(this, InitialActivity.class);
startActivity(i);
}
}
InitialActivity.class
is indeed an Activity
that works fine if I set it to be MAIN
, but trying to start it from MyApplication
that is declared MAIN
generates the error. Probably a very silly question, but am I tackling this all wrong?
Thanks,
Paul