Android Activity Stream (login or register and go to the home page)

I am creating an application that requires user authentication. The first time a user opens the application, you must log in or register in order to go to the main screen of the application, which downloads some messages.

I should mention that the main screen should be FragmentActivity so that the user can move between 2-3 tabs .. this means that I have to have another action (for the login or registration screen) to allow the user to continue working home.

MainActivity | | --> Check If user logged in | | | | | --> Start Login Activity (Or Register From Here) | --> Start Home Activity (FragmentActivity with 2-3 tabs-fragments) 

Right now in the main event, I am looking at general settings if the user is already logged in, and then I start FragmentActivity or login activity if the user is not logged in.

I don't know if this is a problem, but when one of these two actions is running, if I click it, it goes to a blank screen and nothing happens. It seems logical because it is MainActivity and its actually empty. I only have an if statement to jump to the corresponding action.

Is this a good approach or should I develop it in another way?

+2
android android-activity login android-fragmentactivity
Dec 02 '13 at
source share
3 answers

You can complete your main activity immediately after going to the home / login ex screen:

 Intent intent=new Intent(this,Home.class); startActivity(intent); finish(); 

By doing this, if the user clicks the back button on the login page or home page, a blank page will not be visible.

You can also use your main activity as a splash screen, where you show some image and in the background decide to switch to the entrance / home activity.

+5
Dec 02 '13 at 18:09
source share

If you want you to enter a login dialog box that can help you. You can use the code below to create a login dialog box.

 // Create Object of Dialog class final Dialog login = new Dialog(this); // Set GUI of login screen login.setContentView(R.layout.login_dialog); login.setTitle("Login to Pulse 7"); // Init button of login GUI Button btnLogin = (Button) login.findViewById(R.id.btnLogin); Button btnCancel = (Button) login.findViewById(R.id.btnCancel); // Attached listener for login GUI button btnLogin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(Pulse7LoginDialogActivity.this, "Login Sucessfull", Toast.LENGTH_LONG).show(); } }); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { login.dismiss(); } }); // Make dialog box visible. login.show(); 
+1
Dec 02 '13 at 18:14
source share

This code can be used ...

  Intent intent=new Intent(this,Home.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); 
0
Aug 21 '14 at 4:56
source share



All Articles