Skip to content Skip to sidebar Skip to footer

Passing Intent Can't Get Extra();

Hi i can't get logged in already in a web page at mine main activity i passed inten to another activity but i can't get an extract. How can i solve it this is mine main activity

Solution 1:

Intent extras = getIntent().getExtras();
String newString;
if(extras == null) {
    newString= null;
} else {
    newString= extras.getString("username");
}

and for two values both username and password you are giving same key values...please change and try it.


Solution 2:

Use just below code for getting data from intent:-

Intent intent = getIntent();
String username= intent.getStringExtra("username");

Write above code in shouldOverrideUrlLoading method.


Solution 3:

Here

Intent goToNextActivity = new Intent(getApplicationContext(), MainActivity.class);

you are constructing a brand new Intent which is not what you want. You want to use the Intent that started the Activity.

For this reason, you want to use

Intent i = getIntent();

because we can see from the Activity Docs that getIntent()

Return the intent that started this activity.

then get the extras if they are not null

if (i.getExtras() != null) {
    String userName = i.getStringExtra("username");
    String password = i.getStringExtra("password");  // you have a typo in your passing Intent
}

You need your Activity Context for this so it is better/easier to do it in onCreate() instead of your inner-class unless there is a reason you can't do it there.


Solution 4:

Try this way,hope this will help you to solve your problem.

There is two way pass/get data one activity to another activity.

1.add data to intent.

how to put :

Intent goToNextActivity = new Intent();
goToNextActivity.putExtra("username", user_name);
goToNextActivity.putExtra("password", pass_word);

how to get :

String username = getIntent().getStringExtra("username");
String password = getIntent().getStringExtra("password");

2.Add data to bundle and add bundle to intent.

how to put :

Intent goToNextActivity = new Intent();
Bundle bundle = new Bundle();
bundle.putString("username", user_name);
bundle.putString("password", pass_word);
goToNextActivity.putExtras(bundle);

how to get :

String username = getIntent().getExtras().getString("username");
String password = getIntent().getExtras().getString("password");

Post a Comment for "Passing Intent Can't Get Extra();"