No additional intent at startup

Inside the broadcast receiver, I want to run my application (Activity) and transfer some data.

My problem is that the extra features do not seem to carry over into this activity. I am trying to get data inside a function onNewIntent(Intent i).

Any ideas?

Here is my current attempt at BroadcastReceiver :

Intent intSlider = new Intent();
intSlider.setClass(UAirship.shared().getApplicationContext(), SliderMenuActivity.class);
intSlider.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intSlider.putExtra("action", ScreensEnum.Object);
intSlider.putExtra("objectId", objectId);
intSlider.putExtra("objectCode", objectCode);
intSlider.putExtra("userId", userId);

UAirship.shared().getApplicationContext().startActivity(intSlider);

EDIT - Added code used in onNewIntent () and onCreate ()

The following code works fine onCreate()when the application is down. When the application is already running, the same code does not work (i.e. No additional functions) from the function onNewIntent().

Intent intent = getIntent();

if(intent.hasExtra("objectId")) {

    loadDetail(intent.getStringExtra("objectId"), "2w232");
}
+8
source share
5 answers

getIntent(). , , . , onNewIntent .

+9

FLAG_ACTIVITY_SINGLE_TOP singleTop launchMode .

, onNewIntent , getIntent, Intent, . onNewIntent , . , " ".

, : onCreate() SingleTask

+1

, startMode "singleTop" , FLAG_ACTIVITY_SINGLE_TOP startActivity (Intent). , , onNewIntent() , .

​​ , onResume(), .

, getIntent() . setIntent (Intent), .

, .

0

onNewIntent , / onNewIntent Activity . , Intent onNewIntent .

, - , "" , . , , , , setAction, , , .

TL DR: if you encounter this problem with an intent without an action, a call setActionto set an arbitrary action value before sending the intent can fix this.

0
source

You can save the last intent received in a member variable (mLastIntent). You can then use this member in the onResume () method to request additional data.

private Intent mLastIntent;
@Override
protected void onNewIntent(Intent intent) {
    mLastIntent = intent;
};
-1
source

All Articles