Skip to content Skip to sidebar Skip to footer

How To Retrieve Data Using Bundle Object In Android

In my android app, there is one functionality Login with google plus. I have done successfully. but I want to display that data like username, email in textview in next activity. I

Solution 1:

get the value from Intent like because you have set the value in intent you have not set the bundle so you have to get the value explained below

String profilename=getIntent().getStringExtra((PROFILE_USERNAME);
String profle=getIntent().getStringExtra((PROFILE_USERLASTNAME);

Solution 2:

You should safe check if there is a value with that key to avoid nullpointer exception.

Modify your returnValueFromBundles like this

privateStringreturnValueFromBundles(String key) {
String returnedValue="";    
if(!getIntent().getExtras().getString(key).equals(null))
{
    returnedValue = getIntent().getExtras().getString(key).toString();
}
return returnedValue;
}

Solution 3:

You are saving your data in intent so look at your code. You should use bundle this way.. check it and edit your code.

Intenti=newIntent(this, SecondActivity.class);

//Create the bundleBundlebundle=newBundle();
//Add your data from getFactualResults method to bundle
bundle.putString("KEY", value);  
//Add the bundle to the intent
i.putExtras(bundle);

//Fire the second activity
startActivity(i);

}

In your second activity

Bundlebundle= getIntent().getExtras();

//Extract the data…Stringvalue= bundle.getString("KEY");  

Solution 4:

You can put your values into the Bundle like this

Intentii=newIntent(ChooseLoginAccountActivity.this, GoogleplusActivity.class);
    Bundleb=newBundle();
    b.putString(PROFILE_USERNAME, acct.getGivenName());
    b.putString(PROFILE_USERLASTNAME, acct.getFamilyName());
    b.putString(PROFILE_EMAIL_GOOGLE, acct.getEmail());
    ii.putExtras(b);
    startActivity(ii);

Just change your code like above.

Post a Comment for "How To Retrieve Data Using Bundle Object In Android"