Android onNewIntent Uri is always null -
in activity's onnewintent() method, getintent().getdata();
null. goes method before going oncreate()
or other lifecycle function. returns here browser, don't know why getintent().getdata()
null though.
this activity starts browser context.startactivity(new intent(intent.action_view, uri.parse(requesttoken.getauthenticationurl())));
and returns here
@override public void onnewintent(intent intent){ super.onnewintent(intent); uri uri = getintent().getdata(); if (uri != null && uri.tostring().startswith(twitterconstants.callback_url)) {...} }
but uri null.
manifest stuff:
<activity android:name="myapp.mypackage.tweetformactivity" android:configchanges="orientation|keyboardhidden" android:label="@string/app_name" android:launchmode="singleinstance" android:screenorientation="portrait" android:theme="@android:style/theme.black.notitlebar"> <intent-filter> <action android:name="android.intent.action.view" /> <category android:name="android.intent.category.default" /> <category android:name="android.intent.category.browsable" /> <data android:scheme="oauth" android:host="myapp"/> </intent-filter> </activity> static final string callback_url = "oauth://myapp";
what missing here? thanks
you should call getdata()
intent
argument or perform setintent(intent)
before obtaining uri. onnewintent()
doesn't set new intent automatically.
update: so, here're 2 ways can implement onnewintent()
. first replaces old intent new one, when call getintent()
later, receive new intent.
@override protected void onnewintent(final intent intent) { super.onnewintent(intent); // here we're replacing old intent new one. setintent(intent); // can call getintent() , receive new intent. final uri uri = getintent().getdata(); // uri... }
the second way use data new intent leave old 1 as-is.
@override protected void onnewintent(final intent intent) { super.onnewintent(intent); // not call setintent() new intent, // have retrieve uri intent argument. final uri uri = intent.getdata(); // uri... }
of course, can use combination of 2 variants, do not expect receive new intent getintent()
until explicitly set setintent()
.
Comments
Post a Comment