getIntent().getExtra() returns null - android

I have code that direct users to the profile page from the bottom bar.
private void startNewIntent(Class className, String uid){
Intent intent = new Intent(act, className);
intent.putExtra("uid", uid);
act.startActivity(intent);
act.finish();
}
className = DisplayProfile.class;
if(FirebaseAuth.getInstance().getCurrentUser() != null){
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
startNewIntent(DisplayProfile.class, uid);
} else {
startNewIntent(EmailPasswordActivity.class);
}
in ProfileActivity.java
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String uid = getIntent().getStringExtra("uid");
if(uid != null){
...
}
}
I also tried with Bundle = getIntent().getExtra() with the same results. I have seen similar questions. This seem to be the case: getIntent() Extras always NULL
I tried
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
but getIntent().getExtra != null is still false.
Thank you for your help and advice.
Edit: added context for startNewIntent()

Rather than checking in onCreate() check in onNewIntent():
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String uid = getIntent().getStringExtra("uid");
if(uid != null){
...
}
}
#Override
protected void onNewIntent(Intent intent){
super.onNewIntent(intent);
String uid = getIntent().getStringExtra("uid");
if(uid != null){
...
}
}
If it's coming in onNewIntent() this means you are using launchMode for your activity. So this is the behaviour of launch mode.

Avoid ".class" if already present in your class name.
public void startNewIntent(Class className, String uid){
Intent intent = new Intent(act.this, className+".class");
intent.putExtra("uid", uid);
startActivity(intent);
}
Next Phase
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String uid = getIntent().getExtras().getString("uid");
if(uid != null){
...
}
}

Related

Select Address from MapActivity and return back to MainActivity

I recently started Android Development, I wanted to create a form by which I also take user address. In the address field I placed a button to choose their location by using map, I successfully get location but the problem is when I return back to main activity all my fields become empty such as name,phone,email e.t.c.
I want that all my fields remain filled after selecting map location
Here is my Main Activity
public class MainActivity extends AppCompatActivity {
private EditText Name, Phone, Destination;
private Button mBtnAdd;
private String type = "1";
TextView textView;
LocationManager locationManager;
String lattitude,longitude;
private static final int REQUEST_LOCATION = 1;
private static final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Name = (EditText) findViewById(R.id.name);
Phone = (EditText) findViewById(R.id.phone);
Destination = (EditText) findViewById(R.id.destinationAddress);
Intent i = getIntent();
String address = i.getStringExtra ( "address");
Destination.setText(address);
}
private void pickup() {
Intent intent = new Intent(MainActivity.this, MapsActivity.class);
intent.putExtra ( "map_type", "1" );
startActivity(intent);
}
}
Here Is my select location Function in main Map Activity
public void updateLocation(View view) throws IOException {
final EditText location = (EditText) findViewById(R.id.name);
LatLng center = mMap.getCameraPosition().target;
Log.e(TAG, "Center: " + center);
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(center.latitude, center.longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
Log.e(TAG, "addresses: " + addresses);
String address = addresses.get(0).getAddressLine(0);
Intent i = getIntent();
Intent intent = new Intent( MapsActivity.this, MainActivity.class );
intent.putExtra ( "address", address );
startActivity(intent);
}
you need to implement methods onSaveInstanceState and onRestoreInstanceState in your MainActivity:
#Override
protected void onSaveInstanceState(Bundle state) {
/* putting the current instance state into a Bundle */
state.putString(InstanceStateKeys.CURRENT_NAME, this.Name.getText());
state.putString(InstanceStateKeys.CURRENT_PHONE, this.Phone.getText());
state.putString(InstanceStateKeys.CURRENT_DEST, this.Destination.getText());
super.onSaveInstanceState(state);
}
#Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
/* and then obtain these values from the Bundle again */
String currentName = state.getString(InstanceStateKeys.CURRENT_NAME);
String currentPhone = state.getString(InstanceStateKeys.CURRENT_PHONE);
String currentDest = state.getString(InstanceStateKeys.CURRENT_DEST);
/* in order to update the GUI with these values */
if(currentName != null) {this.Name.setText(currentName);}
if(currentPhone != null) {this.Phone.setText(currentPhone);}
if(currentDest != null) {this.Destination.setText(currentDest);}
}
where InstanceStateKeys is just a class with some String constants, for example:
public class InstanceStateKeys {
public static final String CURRENT_NAME = "name";
public static final String CURRENT_PHONE = "phone";
public static final String CURRENT_DEST = "dest";
}
while actually, you should better use .startActivityForResult() to start that MapsActivity and then handle the result within the MainActivity's implementation of .onActivityResult() ...eg. in order to pass back the destination address.
put together it might look alike this ...
/** start the {#link MapsActivity} for a result: */
private void startMapsActivity() {
Intent intent = new Intent(this.getContext(), MapsActivity.class);
intent.putExtra ("map_type", 1);
this.startActivityForResult(intent, RequestCodes.REQUESTCODE_PICK_DESTINATION);
}
then, in order to return that result to the MainActivity:
public void updateLocation(View view) throws IOException {
...
Intent result = new Intent();
result.putExtra ("address", address);
this.setResult(Activity.RESULT_OK, result);
this.finishActivity(RequestCodes.REQUESTCODE_PICK_DESTINATION);
}
finally, when having returned to the MainActivity:
/** handle the result: */
#Override
public void onActivityResult(int requestCode, int resultCode, Intent result) {
String address = null;
if(resultCode == Activity.RESULT_OK && result != null) {
extras = result.getExtras();
if(extras != null) {
address = extras.getString("address", null);
Log.d(LOG_TAG, "the received address is: " + address);
}
}
}
the SDK documentation explains it pretty well: Understand the Activity Lifecycle.

android data passing to another class by a button click

Im trying to pass data from my TestSearch class to GoogleSearch class. I assigned the values of the tEdit test to a string variable and I want to pass that to GoogleSearch class. But my app get crash when I run it.
Button disp=(Button)findViewById(R.id.btn_Search);
disp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
EditText inputTxt = (EditText) findViewById(R.id.editText1);
String str = inputTxt.getText().toString().toLowerCase().trim();
ArrayList<HashMap<String, String>> userList = controller.searchBook(str);
if (userList.size() != 0) {
//Do something
}
else
{
Intent intent = new Intent("com.example.captchalib.GoogleSearch");
intent.putExtra("message", str);
startActivity(intent);
}
}
});
In my GoogleSearch Class I used Below Code to catch the Intent
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_menu);
Intent intent = getIntent();
String message = intent.getStringExtra("message");
((TextView)findViewById(R.id.Receive)).setText(message);
}
why this is happening and how to solve it ?
Logcat
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.captchalib.GoogleSearch (has extras) }
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
Change this line:
Intent intent = new Intent("com.example.captchalib.GoogleSearch");
To:
Intent intent = new Intent(TestSearch.this, GoogleSearch.class);

jav.nullPointer .Exception when using Intent's putExtra() method

I keep getting a NulPpointerException, when I use the Intent's putExtras() method like shown below. It is in the onClick method where I create an intent and call the register activity class. I use android"s account authentication mechanism. Whenever the signUpTxt Textview is clicked, the app crushes and the error log trace below shows. What am I missing?
Here is my source code
public class LoginActivity extends AccountAuthenticatorActivity {
//.......................................
//..........................................
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
actionBar = getSupportActionBar();
actionBar.hide();
mAccountManager = AccountManager.get(getBaseContext());
String accountName = getIntent().getStringExtra(ARG_ACCOUNT_NAME);
mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE);
if (mAuthTokenType == null)
mAuthTokenType = AccountInfo.AUTHTOKEN_TYPE_FULL_ACCESS;
if (accountName != null) {
accountname = ((EditText) findViewById(R.id.txtAccountPhone));
accountname.setText(accountName);
}
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
login();
}
});
signUpTxt = (TextView) findViewById(R.id.txtSignUp);
signUpTxt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Since there can only be one AuthenticatorActivity, we call the sign up activity, get his results,
// and return them in setAccountAuthenticatorResult(). See finishLogin().
Intent signup = new Intent(getBaseContext(), RegisterActivity.class);
signup.putExtras(getIntent().getExtras());
startActivityForResult(signup, REQ_SIGNUP);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// The sign up activity returned that the user has successfully created an account
if (requestCode == REQ_SIGNUP && resultCode == RESULT_OK) {
finishLogin(data);
} else
super.onActivityResult(requestCode, resultCode, data);
}
public void login() {
final String userName = ((TextView) findViewById(R.id.txtAccountPhone)).getText().toString();
final String userPass = ((TextView) findViewById(R.id.txtAccountPassword)).getText().toString();
final String accountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);
new AsyncTask<String, Void, Intent>() {
#Override
protected Intent doInBackground(String... params) {
Log.d("Slime", TAG + "> Started authenticating");
String authtoken = null;
Bundle data = new Bundle();
try {
authtoken = AccountInfo.sServerAuthenticate.userSignIn(userName, userPass, mAuthTokenType);
data.putString(AccountManager.KEY_ACCOUNT_NAME, userName);
data.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
data.putString(AccountManager.KEY_AUTHTOKEN, authtoken);
data.putString(PARAM_USER_PASS, userPass);
} catch (Exception e) {
data.putString(KEY_ERROR_MESSAGE, e.getMessage());
}
final Intent res = new Intent();
res.putExtras(data);
return res;
}
#Override
protected void onPostExecute(Intent intent) {
if (intent.hasExtra(KEY_ERROR_MESSAGE)) {
Toast.makeText(getBaseContext(), intent.getStringExtra(KEY_ERROR_MESSAGE), Toast.LENGTH_SHORT).show();
} else {
finishLogin(intent);
}
}
}.execute();
}
private void finishLogin(Intent intent) {
Log.d("Slime", TAG + "> finishLogin");
String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
String accountPassword = intent.getStringExtra(PARAM_USER_PASS);
final Account account = new Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
if (getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) {
Log.d("Slime", TAG + "> finishLogin > addAccountExplicitly");
String authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
String authtokenType = mAuthTokenType;
// Creating the account on the device and setting the auth token we got
// (Not setting the auth token will cause another call to the server to authenticate the user)
mAccountManager.addAccountExplicitly(account, accountPassword, null);
mAccountManager.setAuthToken(account, authtokenType, authtoken);
} else {
Log.d("Slime", TAG + "> finishLogin > setPassword");
mAccountManager.setPassword(account, accountPassword);
}
setAccountAuthenticatorResult(intent.getExtras());
setResult(RESULT_OK, intent);
finish();
}
}
This is the error Logs from the logcat
06-30 14:53:46.109: E/AndroidRuntime(6015): FATAL EXCEPTION: main
06-30 14:53:46.109: E/AndroidRuntime(6015): java.lang.NullPointerException
06-30 14:53:46.109: E/AndroidRuntime(6015): at android.os.Bundle.putAll(Bundle.java:281)
06-30 14:53:46.109: E/AndroidRuntime(6015): at android.content.Intent.putExtras(Intent.java:4828)
06-30 14:53:46.109: E/AndroidRuntime(6015): at com.rowland.slumber.LoginActivity$2.onClick(LoginActivity.java:86)
06-30 14:53:46.109: E/AndroidRuntime(6015): at android.view.View.performClick(View.java:2485)
06-30 14:53:46.109: E/AndroidRuntime(6015): at android.view.View$PerformClick.run(View.java:9080)
06-30 14:53:46.109: E/AndroidRuntime(6015): at android.os.Handler.handleCallback(Handler.java:587)
Edit, this is line 86
public void onClick(View v) {
// Since there can only be one AuthenticatorActivity, we call the sign up activity, get his results,
// and return them in setAccountAuthenticatorResult(). See finishLogin().
Intent signup = new Intent(getBaseContext(), RegisterActivity.class);
signup.putExtras(getIntent().getExtras()); //LINE 86
startActivityForResult(signup, REQ_SIGNUP);
}
});
}
Iam passing the extras from Authenticator.java which extends AbstractAccountAuthenticator, in the addAccount() method
#Override
public Bundle addAccount(AccountAuthenticatorResponse response,
String accountType, String authTokenType,
String[] requiredFeatures, Bundle options)
throws NetworkErrorException {
Bundle result;
if (hasAccount(mContext)) {
result = new Bundle();
Intent i = new Intent(mContext, LoginActivity.class);
i.putExtra(LoginActivity.ARG_ACCOUNT_TYPE, accountType);
i.putExtra(LoginActivity.ARG_AUTH_TYPE, authTokenType);
i.putExtra(LoginActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
i.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,response);
result.putParcelable(AccountManager.KEY_INTENT, i);
return result;
}
Based on the API:
Intent.getExtras() returns:
the map of all extras previously added with putExtra(), or null if none have been added
My guess would be that you are not passing in any extras and therefore passing null to the Intent.putExtras() method... Or if you think you are you may be doing so incorrectly.
From
getIntent().getStringExtra(ARG_ACCOUNT_NAME);
I can say thay you have used putStringExtra method, instead of putExtras.
Therefore, when you try getIntent().getExtras it is null.

android: onSaveInstanceState ()

I try to pass a string from one activity to another activity.
This is the coding in Activity A:
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString("UserName", UserName);
Log.i(Tag, "UserName1: "+ UserName);
super.onSaveInstanceState(savedInstanceState);
}
In Activity B I use this code to get the string:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_item);
setUpViews();
if (savedInstanceState != null){
UserName = savedInstanceState.getString("UserName");
}
Log.i(Tag, "UserName2: "+ UserName);
}
But the logcat shown the first log "UserName1" when I clikc the open to Activity B,
and show the second log "UserName2" as "null".
May I know what wrong with my code?
What I want to do is Activity A pass the String in Activity B when I click the "button" and intent to Activity B. So I can get the String value in Activity B.
Any Idea? Cause I getting error when using intent.putStringExtra() and getintent.getStringExtra(), so I change to use onSaveInstanceState (), but still having problem.
EDIT:
This is my original code, I can get the String in Activity B, but unexpected I can't save my data in Sqlite. If remove the putString Extra then everything go smoothly.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent addItem = new Intent(ItemActivity.this, AddEditItem.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
addItem.putStringExtra("UserName", UserName);
Log.e(Tag, "UseName: "+ UserName);
startActivity(addItem);
return super.onOptionsItemSelected(item);
}
Code in Activity B:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_item);
setUpViews();
UserName = (String) getIntent().getStringExtra("UserName");
Log.e(Tag, "UserName3: "+ UserName);
}
Full code for Activity B:
public class AddEditItem extends Activity implements OnItemSelectedListener {
private static final String Tag = null;
private EditText inputItemName;
private EditText inputItemCondition;
private EditText inputEmail;
private Button btnGal, btnConfirm;
private Bitmap bmp;
private ImageView ivGalImg;
private Spinner spinner;
String[] category = {"Books", "Clothes & Shoes", "Computer", "Electronics", "Entertainment", "Food & Drinks",
"Furnitures", "Mobile Phone", "Other", "UKM"};
String selection;
String filePath, itemName, itemCondition;
String UserName, user;
private int id;
private byte[] blob=null;
byte[] byteImage2 = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_item);
setUpViews();
if (savedInstanceState != null){
UserName = savedInstanceState.getString("UserName");
}
Log.e(Tag, "UserName2: "+ UserName);
//UserName = (String) getIntent().getStringExtra("UserName");
//Log.e(Tag, "UserName3: "+ UserName);
}
private void setUpViews() {
inputItemName = (EditText)findViewById(R.id.etItemName);
inputItemCondition = (EditText)findViewById(R.id.etItemCondition);
inputEmail = (EditText)findViewById(R.id.etEmail);
ivGalImg = (ImageView) findViewById(R.id.ivImage);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(AddEditItem.this, android.R.layout.simple_spinner_dropdown_item, category);
spinner = (Spinner)findViewById(R.id.spnCategory);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
Bundle extras = getIntent().getExtras();
if (extras != null) {
id=extras.getInt("id");
user=extras.getString("user");
inputItemName.setText(extras.getString("name"));
inputItemCondition.setText(extras.getString("condition"));
inputEmail.setText(extras.getString("email"));
selection = extras.getString("category");
byteImage2 = extras.getByteArray("blob");
if (byteImage2 != null) {
if (byteImage2.length > 3) {
ivGalImg.setImageBitmap(BitmapFactory.decodeByteArray(byteImage2,0,byteImage2.length));
}
}
}
btnGal = (Button) findViewById(R.id.bGallary);
btnGal.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 0);
}
});
btnConfirm = (Button) findViewById(R.id.bConfirm);
btnConfirm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (inputItemName.getText().length() != 0 && inputItemCondition.getText().length() != 0
&& inputEmail.getText().length() != 0) {
AsyncTask<Object, Object, Object> saveItemTask = new AsyncTask<Object, Object, Object>() {
#Override
protected Object doInBackground(Object... params) {
saveItem();
return null;
}
#Override
protected void onPostExecute(Object result) {
Toast.makeText(getApplicationContext(),
"Item saved", Toast.LENGTH_LONG)
.show();
finish();
}
};
saveItemTask.execute((Object[]) null);
Toast.makeText(getApplicationContext(),
"Item saved reconfirm", Toast.LENGTH_LONG)
.show();
} else {
AlertDialog.Builder alert = new AlertDialog.Builder(
AddEditItem.this);
alert.setTitle("Error In Save Item");
alert.setMessage("You need to fill in all the item details");
alert.setPositiveButton("OK", null);
alert.show();
}
}
});
}
private void saveItem() {
if(bmp!=null){
ByteArrayOutputStream outStr = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, outStr);
blob = outStr.toByteArray();
}
else{blob=byteImage2;}
ItemSQLiteConnector sqlCon = new ItemSQLiteConnector(this);
if (getIntent().getExtras() == null) {
sqlCon.insertItem(UserName, inputItemName.getText().toString(),
inputItemCondition.getText().toString(),
inputEmail.getText().toString(),
selection, blob);
}
else {
sqlCon.updateItem(id, UserName, inputItemName.getText().toString(),
inputItemCondition.getText().toString(),
inputEmail.getText().toString(),
selection, blob);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode,Intent resultdata) {
super.onActivityResult(requestCode, resultCode, resultdata);
switch (requestCode) {
case 0:
if (resultCode == RESULT_OK) {
Uri selectedImage = resultdata.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
// Convert file path into bitmap image using below line.
bmp = BitmapFactory.decodeFile(filePath);
ivGalImg.setImageBitmap(bmp);
}
}
}
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// TODO Auto-generated method stub
TextView tv = (TextView)view;
selection = tv.getText().toString();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
onSaveInstanceState is not used in that purpose, its used to save your activity state on for example orientation change, or when you leave an activity and get back to it.
What you need is to use intents.
Other than starting activity, intents can also carry some information throughout app, like this:
This would be activity 1:
Intent = new Intent (getApplicationContext(), Activity2.class);
intent.putExtra("UserName", UserName);
startActivity(intent);
and to recover it in second activity use:
String username = getIntent().getExtras().getString("UserName");
May I know what wrong with my code?
onSaveInstanceState() has nothing to do with passing data between activities. Instead, you need to put your string in an extra on the Intent used with startActivity().
Cause I getting error when using intent.putExtra() and getintent.getExtra()
Since that is the correct approach (albeit using getStringExtra()), please go back to it and fix whatever error you are encountering.

I cant send Extra for singleTask activity Android

I use singleTask activity in my application.
Order activities A->B->C->B
I put extra on A and then get it on B, then I go to C and try putExtra for B, but on B I don't see it.
If I use default android:launchMode, it work ok.
you have to carry extra between intents.
A -step1-> B -step2-> C -step3-> B
step1
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String extraString;
Bundle extras = getIntent().getExtras();
if (extras == null) {
extraString = null;
System.out.println("null extra");
} else {
extraString = extras.getString("extra");
System.out.println("from " + extraString);
}
Intent intent = new Intent(C.this,B.class);
intent.putExtra("extra", extraString);
startActivity(intent);
};
step2
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String extraString,extraString2;
Bundle extras = getIntent().getExtras();
if (extras == null) {
extraString = null;
System.out.println("null extra");
} else {
try
{
extraString = extras.getString("extra");
System.out.println("from " + extraString);
{
catch{}
}
// CATCH EXTRA STRING2
if (extras == null) {
extraString2 = null;
System.out.println("null extra");
} else {
try
{
extraString2 = extras.getString("extra2");
System.out.println("from " + extraString2);
{
catch{}
}
Intent intent = new Intent(C.this,B.class);
intent.putExtra("extra", extraString);
startActivity(intent);
};
step3
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String extraString
Bundle extras = getIntent().getExtras();
if (extras == null) {
extraString = null;
System.out.println("null extra");
} else {
extraString = extras.getString("extra");
System.out.println("from " + extraString);
}
Intent intent = new Intent(C.this,B.class);
intent.putExtra("extra2", extraString);
startActivity(intent);
};

Categories

Resources