my problem is to pass a string between 3 activity..I explain how I did it.
the first activity called the loginActiviy where I do this.
//OnCreate ecc before this
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
data.putExtra("Name", Name);
super.onActivityResult(requestCode, resultCode, data);
}
public void onResume()
{
super.onResume();
finish();
}
when the activity ends is called finish () ( maybe that's the problem I do not know ) then control passes to the first activity, where I do this
//OnCreate ecc before
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Bundle extras = data.getExtras();
String name = null;
if(extras != null) {
name = extras.getString("Name");
}
super.onActivityResult(requestCode, resultCode, data);
try
{
Intent people = new Intent(this, MainPeopleActivity2.class);
people.putExtra("Name", name);
startActivity(people);
this.finish();
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), e, Toast.LENGTH_LONG).show();
}
}
Now start third activity , where take the intent doing this
String name;
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
name= null;
} else {
name= extras.getString("Name");
}
} else {
name = (String) savedInstanceState.getSerializable("Name");
}
But as you can imagine this is not the case , the string is empty.
where am I wrong ? Thanks in advance.
This is full Login Class
public void onSuccess(LoginResult loginResult) {
GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (response.getError() != null) {
} else {
id = user.optString("id");
firstName = user.optString("first_name");
lastName = user.optString("last_name");
email = user.optString("email");
Log.i(TAG,"User ID "+ id);
Log.i(TAG,"Email "+ email);
}
Name = firstName + " " + lastName;
Toast.makeText(getApplicationContext(), "Log in with " + Name, Toast.LENGTH_LONG).show();
}
}).executeAsync();
}