I have a button
When the user clicks on it, it will be redirects to a registration page
I want user to be redirect to a loading page after clicking on the signup button
And then i want the user to be returns to the main page
And I want a message with the title of "your registration successfully completed" to be display to the user
And after a few seconds, this alert message to be hide
Follow this way to activity switch
Intent intent = new Intent(RegistrationActivity.this, DashBaord.class);
startActivity(intent);
finish();
Suppose your registration activity is RegistrationActivity where you will showing your sign up button and HomeActivity will be the activity which will be shown to user after registering to the app successfully.
You have to maintain some variable so you can know if that variable is registered or not.
boolean isUserRegistered ;
if a user is registered successfully then,
isUserRegistered = true;
and save this varibale using SharedPreferences.For more info about SharedPreferences :
Android Shared preferences example
In the splash activity or some other activity where you will decide which activity to open put this check,
if(isUserRegistered)
//start HomeActvity
else
//start RegistrationActivity
I think your requirement is to create a signup Activity and on completing signup, the user needs to be redirected to Homepage and display a dialog with content "your registration successfully completed".
First of all you need to create a signup Activity. Then when clicking signup, display a custom dialogfragment indicating Loading. Show this dialog when user clicks the signup button. Then make an api request to complete the signup. On response of this api request, dismiss the custom dialogfragment and go to Home activity.
Creating a dialog Fragment : link
On going to Home activity, you need to pass the response of the API request along with intent. In the Home Activity, you can get the value passed along with the intent to HomeScreen to get the message you want to display. You can use an Alert Dialog or custom DialogFragment for displaying the info.
To dismiss the dialog after x seconds, you can use postDelayed(Runnable, long).
Creating a Post Delayed : link
Related
I am new to Android.I am building an app which will send/retrieve data to/from a server.So what I did is I created a login page and gave credentials for each user.So,once the user logs in,I want the user to be logged in until he signs out.I mean the log in screen should not be visible the next time the user opens the app.So, I have done that using SharedPreferences in android.
private EditText mobile,password;
SharedPreferences sharedPreferences;
mobile = (EditText) findViewById(R.id.mobileET);
password = (EditText) findViewById(R.id.passwordET);
String mob = mobile.getText().toString();
String pass = password.getText().toString();
sharedPreferences = getSharedPreferences(MyPREFERENCES,Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(MOBILE,mob);
editor.putString(PASSWORD,pass);
editor.commit();
And when the user comes to the next screen,if the user clicks on Back button,the user should not be taken to the Login screen. So, I have used the below code in the next Activity which is the activity that comes after a user is logged in.
#Override
public void onBackPressed() {
moveTaskToBack(true);
}
So,this is working fine and when the user clicks on the next Back button,the app is closed and if the user opens the app again,the Second activity is shown.
So,what I want is to for the Second Activity to be loaded with some data from the server whenever the app is opened.The Second Activity should fetch data from the server automatically when the app is opened.Earlier,what I did was I ran a PHP Script to fetch data from the server when the Login button is clicked. But now,since the Login screen will appear only once I am not able to figure out how to fetch the data and reload it with the latest details every time the app is opened.Also there are some validations to be done like the user can input data only once per day.So,when the app is opened,it should also check for that and if the user has already given his/her input for the day,he/she should be redirected to a "Thank You" screen.And if again the user opens the app the next day,it should open the Second Activity where the user can give his input.So how do I do these validations in the Second Activity which comes after the Login Activity. Can anyone please help me with this?
you have to call the service on second activity's on create method after setContentView() and fetch the data from the shared preferences and pass that data to the php script and catch response and show the data to the apropreate location.
and the credentials you want to give for one day duration then check the entry with the system date and validate it. if it is belong to the same date then it will pass to the thank you page otherwise it allow user to move to second activity.
I have an app with multiple Activity classes. In one part, one is a main screen and the next is a login. The user would open the login screen and enter their info and press a button to submit it. The resulting code opens up an AlertDialog to tell them the registration status, along with some other information. If the registration itself was successful, they will return to the previous activity. But this makes any AlertDialog disappear with it.
I want the background to return to the previous activity so they can see the home page start updating, but I want them to see the alert message long enough to read it.
Yes this is possble. By using a service you can display an alertbox which runs in foreground for a long time. I have done thissame kind of thing for a news app.
It will run in foreground for a long time and when you want to switch you can stop the service than it will dismiss the alert box-.
In my case I displayed a custom view with buttons in the foreground.
I have a login screen in my Android App and after login the main screen comes.
What is the most appropriate way to not allow the login screen to appear again after successful login.
Should we put a check in the onCreate of the login Activity.
Set up appropriate Flag to the Intent of main screen
if this is not appropriate what would be the most appropriate flag for this.
Another problem is that from the main screen we have links to various sections of the App.
The user may leave the app at any page of any subsection of the app.
For eg:
the user may view various products by using the product section from the Main Screen.
Is it possible to always start off from this main screen even when there is some error in some subsection activity. For eg:
if any product page crashes , the app returns to Starting Page of Products whereas we require it to start from the Main Screen.
Is it possible through some flag setting in the activity tag or do we need to check some property in onCreate and accordingly navigate back to Main-Screen.
Kindly update.
Thanks
You can use Intent Flag for such result.in my app i use below code -
Intent i = new Intent(mContext, DashBoardActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
It this way login screen not appear after login if user presses back button.
Also set a flag in SharedPreference say is_user_login = true and in next launch of app check preference value and take action according to it.
Hope it will help you.
What is the most appropriate way to not allow the login screen to appear again after successful login.
You can use a flag or use a sharedPreference for this to maintain the state of the login.
Is it possible to always start off from this main screen even when there is some error in some subsection activity. For eg: if any product page crashes , the app returns to Starting Page of Products whereas we require it to start from the Main Screen.
Do proper exception handling and in the catch block redirect to main screen and call finish()
prevent login screen using this link
Add into your MainScreen remove this line super.onBackPressed();
#Override
public void onBackPressed() {
moveTaskToBack(true);
}
if any problem just ping me
I have an activity contains facebook login button, and when login is done, new activity is launched.
I've see that when i login, a new blank activity (maybe the facebook LoginActivity) is launched and a spinner is showed. When login is done, that activity end and focus return for a moment to my activity contains facebook button login before start new activity. Could i change behavior during login?
I would only show a spinner inside current Activity
My program has a email function. There are two activities, A and B. The email function is in activity B. When I click email button, it will pop up a dialog to let user to choose whose to send. then will call email.
The problem is, every time when I click send, it will be return to the dialog(choose list). Is there anyway to let the program return to activity A automatilcally when user click send button. I can't do a onclick listerner becase email system is out of my control.
thanks.
in the on click function of the dialogue that you have implemented try calling dialog.dismiss() before switching to Activity B.
You can finish activity b manually by calling finish()