I am writing an app that requires you to be logged in to a service before using it. From my understanding of android so far, you have to choose which activity to launch when you open from the launcher in the manifest. I don't know which activity i want to launch at compile time. I want the user to click the icon, then I check and see if they're logged in, then decide based on that whether to launch the login activity, or the main app activity. Is there a way to do this?
+3
A:
No, since you have to run some code, there's no way to declaratively (in manifest) to say this. You have to launch an activity (set in manifest), then have this activity decide based on if the user is logged on or not what second activity to launch via Intent:
final Class<? extends Activity> activityClass;
if(userIsLoggedOn())
activityClass = LoggedOnActivity.class;
else
activityClass = LogInActivity.class;
Intent newActivity = new Intent(context, activityClass);
context.startActivity(newActivity);
Ricardo Villamil
2010-05-05 19:29:29