Reputation: 488
I am sending values using intent.putExtras
but I am getting null values on the next activity. Here is my code for intent
if (id == R.id.save_times) {
Intent intent = new Intent(AlertTimerSelector.this, Dashboard.class);
intent.putExtra(AppHelper.LOW_LEVEL, dialogHelper.getPicker_value1());
Log.d("AlertTimer", "onOptionsItemSelected: " + dialogHelper.getPicker_value1());
intent.putExtra(AppHelper.MEDIUM_LEVEL, dialogHelper.getPicker_value2());
Log.d("AlertTimer", "onOptionsItemSelected: " + dialogHelper.getPicker_value2());
intent.putExtra(AppHelper.HIGH_LEVEL, dialogHelper.getPicker_value3());
Log.d("AlertTimer", "onOptionsItemSelected: " + dialogHelper.getPicker_value3());
intent.putExtra(AppHelper.ALERT_TIME_ID_TEXT,AppHelper.ALERT_TIME_ID);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
return true;
}
And this is my next Activity code where i am retrieving these values in onNewIntent
@Override
protected void onNewIntent(Intent intent) {
Bundle bundle=getIntent().getExtras();
if (bundle.getString(AppHelper.ALERT_TIME_ID_TEXT).equals(AppHelper.ALERT_TIME_ID)){
low_level_time=bundle.getString(AppHelper.LOW_LEVEL);
medium_level_time=bundle.getString(AppHelper.MEDIUM_LEVEL);
high_level_time=bundle.getString(AppHelper.HIGH_LEVEL);
}
if (bundle.get(AppHelper.SLEEP_TIME_ID_TEXT).equals(AppHelper.SLEEP_ID)){
sleep_time_hrs=bundle.getString(AppHelper.SLEEP_TIME_HOURS);
sleep_time_mins=bundle.getString(AppHelper.SLEEP_TIME_MINUTES);
wakeup_time_hrs=bundle.getString(AppHelper.WAKEUP_TIME_HOURS);
wakeup_time_mins=bundle.getString(AppHelper.WAKEUP_TIME_MINUTES);
}
Log.d(TAG, "onNewIntent: "+bundle.toString());
super.onNewIntent(intent);
}
please help me out with this.Thanx
onNewIntent is not getting called.I don't know why?
Upvotes: 1
Views: 472
Reputation: 868
The activity in which you are receiving intent,add the flag in manifest file under that activity
android:launchMode="singleTop"
Upvotes: 0
Reputation: 426
onNewIntent() will be called only when FLAG_ACTIVITY_SINGLE_TOP is called. Since you are using 3 flags in activity, there may be some problem. Use only FLAG_ACTIVITY_SINGLE_TOP and try.
or
Move your values retrieving code to onCreate and try.
Upvotes: 0
Reputation: 2770
You have to get your data for example on the onCreate
method like this
String myString = getIntent().getStringExtra(AppHelper.LOW_LEVEL);
OnNewIntent
is called when you try to start the same activity that has a launchmode equal to singleTop
(or have it setted programmatically)
For extra information read this doc
Upvotes: 0
Reputation: 4032
Try This:
Intent intent=getIntent();
if(intent!=null)
{
low_level_time=intent.getStringExtra(AppHelper.LOW_LEVEL);
//other values like above..
}
Upvotes: 0
Reputation: 1193
First, get the intent which has started your activity using the getIntent() method:
Intent intent = getIntent();
If your extra data is represented as strings, then you can use intent.getStringExtra(String name) method. In your case:
String id = intent.getStringExtra(AppHelper.LOW_LEVEL);
Upvotes: 1