Android back to activity after validate - android

I'm making a registration form with 5 steps (5 activities, Similar to facebook signup form).
The 1st activity is to put email
The 2nd activity is to put name and so on. After the user complete all steps, i validate the field email (to avoid being duplicated) from the server side. What i want is, if the user email exist, i want to go back to 1st activity so the user can enter other email and the submit the form again to the server. Whats the best way to do that?
Thanks

In your LastActivity after some action.
Intent intent = new Intent(this,FirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent );
This flag clear recent Activity in the activities stack.

Related

Duplicate activity to launch many instances of same activity using unique identifier

I am building a chat client and chatting with every user opens same activity ChatActivity passing an username as intent extras like this one.
Intent.putExtra("user", username);
Where username being the one one you are chatting with. After extras are sent, ChatAcitivity opens up, handles the extra's username and work accordingly. Now, if i am chatting with multiple users at once, say user1 and user2, each time the activity restarts to handle the data. How can i preserve the chat with both the user and open up the already initialized activity so as to reduce load both to the server & user.
I want something to identify the intent that needs to be opened like chatting with user1 brings user1 ChatActivity to the front and so i can use:
resultIntent.setFlags(Intent.FLAG_ACTIVITY_USER1ACTIVITY_BROUGHT_TO_FRONT_);
or something to call that up.
How can i do that??
I understand you want to have 'duplicate' instances of the ChatActivity, one for each user. You can use the FLAG_ACTIVITY_NEW_DOCUMENT flag, the document being a conversation with a specific user :
// the URI is used as a document ID
// a stack / activity with the same id will be reused
// and the intent passed to onNewIntent()
// otherwise a new activity is created
startIntent.setData(Uri.parse("http://my.domain.net/users/" + username));
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
Please note that each conversation will have its own entry in the Recents screen (Overview screen). This may or may not be what you want.

clearing all open previous activities not working in android 5.0

My app has a log in MainActivity. By tapping on a link a SecondActivity starts and the user can sign up. After the user completes the form an email is sent with a deep link to activate the account. When the user taps that link the MainActivity starts again indicating that the account was activated and that the user can log in. The problem is that in android 4.3 the previous activities get clear, but not in Android 5:
This is part of the code I'm using when the user taps the deep link:
Intent toLaunchMainActivityAgain = new Intent(this, MainActivity.class);
toLaunchMainActivityAgain.addFlags(toLaunchMainActivityAgain.FLAG_ACTIVITY_CLEAR_TOP);
toLaunchMainActivityAgain.setFlags(toLaunchMainActivityAgain.FLAG_ACTIVITY_MULTIPLE_TASK);
toLaunchMainActivityAgain.setFlags(toLaunchMainActivityAgain.FLAG_ACTIVITY_NEW_TASK);
When you are trying to launch another activity, call below to make sure Android Task Manager doesn't store the activity you are leaving
startActivity(new Intent(MainActivity.this, OtherActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK));
When I want to then go back to another activity from my current one, I simply call
finish();

Android: userId - GET PHP alternative?

so I have an app where users have accounts/profiles, when say you type name and surname in search it would bring to activity called ProfileViewer and display that users details.
In PHP I would have link like:
John Sample
So when user clicks on that - it would go to PHP page called profile.php and load data from MySQL database WHERE userid=xxx.
So what's the alternative in Android? I am a bit lost, what are some of my options on how to identify which userID is Activity loading?
Could I use putExtra("userId", xxx) and then use getExtra()?
In other words: How can I make one activity act like page which accepts 1 param and then uses it on opening?
Intent extras are generally the way to go in these cases.
From the first activity you would:
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("userId", 1);
startActivity(intent);
And you then retrive the information in the second activity like this:
getIntent().getIntExtra("userId");

How to display a welcome message including username from another activity in android?

Here is what I want to do, I have an android login form with username and password, after the user enters his credentials and login, the next form should display on top of the page welcome,+username entered from the login page! can someone please help me??
I'm new to android development and don't know how to go about this. Thanks
You can use intent to pass username from one activity to another.
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtra("username","enteredusername");
startActivity(intent);
And in SecondActivity
String name = getIntent().getStringExtra("username");
Now use the name and display the welcome +name
http://developer.android.com/training/basics/firstapp/starting-activity.html
In order to send data from one activity to another, you need to use intents. So, in your login activity, you would launch your welcome activity like this:
Intent intent = new Intent(LoginActivity.this, WelcomeActivity.class);
intent.putextra("userName","value");
startActivity(intent);
Then, in your welcome activity, you need to retrieve the extra data, like so:
String data= getIntent().getStringExtra("userName");
There are a multitude of examples that can be found via Google, and many questions similar/identical to this have been answered previously on SO.
You can store the username in sqlite or sharedpreferences to get the username across all your application.

Android Activity choose

I need to choose if I should run one activity or another depends on authorization. If you have no account in AccountManager I want to show RegistrationAcitivity in other situation I want to show LoginActivity. What is the best pattern to do that? Where I need to put the code which is checking that? In one of those activities?
You can check the condition is user is already register then move to AccountManager .
Intent intent = new Intent(this,AccountManager.class);
startActivity(intent);
if not then redirect him to RegistrationAcitivity
Intent intent = new Intent(this,RegistrationActivity.class);
startActivity(intent);
For that you can set flags.
or store data either in SharedPreferences or Database
You can put the code in Registration Activity, check for accounts there and if available redirect him to login activtiy

Categories

Resources