3

For the first time use of the application I will show the user with a login screen which i will defined in manifest file as "android.intent.action.MAIN". After a successful login, each time application starts I want the user to see the home screen. Please let me know how i can achieve this.

Also please let me know is there any way I can change the MAIN activity programmatically after a successful login, So that I can redirect to the home screen.

Thanks,

Vijay

vijaykumarg
  • 181
  • 1
  • 16
  • 1
    After Successful login you can store your data in SharedPreferences and when again application start check the SharedPreferences. If there is value then start other activity else login setContentView. – kalpana c Jul 10 '12 at 11:26
  • 1
    I think this link will help you.... [link](http://blog.donnfelker.com/2011/02/17/android-a-simple-eula-for-your-android-apps/) Thanks.... – user4232 Jul 10 '12 at 11:27
  • @casperOne Why this question has been closed? – Alexander Kulyakhtin Jul 10 '12 at 14:58
  • "Gimme teh codez" questions are usually closed as NARQ – casperOne Jul 10 '12 at 14:58
  • @casperOne I don't think that's the case here... Although, anyway, the question has been answered and in various ways, so that's not a problem. – Alexander Kulyakhtin Jul 10 '12 at 15:25
  • I dont know whats wrong with the question. But anyways you guys have saved my time & thanks for all the answers. Thanks Alex for the solution. It worked!! – vijaykumarg Jul 10 '12 at 15:43

4 Answers4

1

What if you subclass Application class and call the activity you need from your Application's onCreate() ? And in the manifest you remove that intent.MAIN.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
  • Thanks for that. will implement it. – vijaykumarg Jul 10 '12 at 12:42
  • I have subclassed the Application & added it under the application tag in manifest. As suggested I removed the Intent-Filter for the Login Activity. Now the Manifest file does not contain Intent.Main anymore. Application is successfully installed, but it is not showing in the list. – vijaykumarg Jul 10 '12 at 23:42
1

I don't think you can set the main activity programmatically, but you can set a boolean in your sharedPreferences. If this boolean is true, then you call your HomeActivity, and finish your LoginActivity.

Hope this helps

AMerle
  • 4,354
  • 1
  • 28
  • 43
0

I would, from the login screen simply call the home screen. Or from the home screen, if the login details are not saved/ valid, then show the login screen.

Basically, it is not necessary or a good programming practice to do what you are asking.

Will Richardson
  • 7,780
  • 7
  • 42
  • 56
0

When you have successfully logged in, call finish(); in the main activity which will remove it from the stack. Then in your HomeScreenActivity, override the back button to act as the home button:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        moveTaskToBack(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
Carnal
  • 21,744
  • 6
  • 60
  • 75