Monday, 15 March 2010

android - Calling Activity from notification forces new task resulting in a "blank" activity -



android - Calling Activity from notification forces new task resulting in a "blank" activity -

i have app might receive force notification. force notification should start activity when user clicks on it. pretty standard. got working on emulator , on galaxy s4, nexus device giving me head ache.

at first got:

java.lang.securityexception: permission denial: start intent

on particular activity, "fixed" inserting android:exported="true" activity in manifest xml. not sure if right approach, couldn't find improve one.

now getting

​startactivity called non-activity context; forcing intent.flag_activity_new_task for: intent

activity gets started, these variables seem "null":

opponentusername = getintent().getextras().getstring("opponentusername"); gameid = getintent().getextras().getstring("gameid");

resulting in "empty" activity.

this how launch activity in broadcastreceiverclass:

notification n = new notification(icon, tickertext, when); intent intent = new intent(ctx, ss9chatactivity.class); intent.putextra("opponentusername", dataobject.getstring("oppo")); intent.putextra("gameid", dataobject.getstring("game")); pendingintent pi = pendingintent.getactivity(ctx, 0, intent, 0); n.setlatesteventinfo(ctx, "game", tickertext, pi); n.flags |= notification.flag_auto_cancel; n.defaults |= notification.default_vibrate; nm.notify(1, n);

what tried far is, inserting android:launchmode="singletop" in activity, didn't seem prepare it

so doing wrong here? why nexus devices different emulator , galaxy s4? there app works fine.

thanks in advance help!

here manifest in full

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.testapp" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="14" android:targetsdkversion="18" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.wake_lock" /> <uses-permission android:name="android.permission.receive_boot_completed" /> <uses-permission android:name="android.permission.vibrate" /> <uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="com.google.android.c2dm.permission.receive" /> <permission android:protectionlevel="signature" android:name="com.testapp.permission.c2d_message" /> <uses-permission android:name="com.testapp.permission.c2d_message" /> <application android:name=".app" android:allowbackup="true" android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/noanimtheme"> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <activity android:name="com.testapp.splashscreenactivity" android:label="@string/app_name" android:screenorientation="sensorportait" android:windowsoftinputmode="statehidden" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="mainactivity" android:label="@string/app_name" android:screenorientation="sensorportait" android:windowsoftinputmode="statehidden|adjustresize"/> <activity android:name="ss9chatactivity" android:launchmode="singletop" android:exported="true" android:label="@string/app_name" android:screenorientation="sensorportait" android:windowsoftinputmode="statehidden|adjustresize"/> <activity android:name="com.facebook.loginactivity" android:label="@string/app_name" /> <meta-data android:name="com.facebook.sdk.applicationid" android:value="@string/facebook_app_id"/> <service android:name="com.parse.pushservice" /> <receiver android:name="com.parse.parsebroadcastreceiver"> <intent-filter> <action android:name="android.intent.action.boot_completed" /> <action android:name="android.intent.action.user_present" /> </intent-filter> </receiver> <receiver android:name="com.parse.gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send"> <intent-filter> <action android:name="com.google.android.c2dm.intent.receive" /> <action android:name="com.google.android.c2dm.intent.registration" /> <category android:name="com.testapp" /> </intent-filter> </receiver> <receiver android:name="com.testapp.pushbroadcastreceiver" android:exported="false" > <intent-filter> <action android:name="com.testapp.push" /> </intent-filter> </receiver> <activity android:name="com.google.android.gms.ads.adactivity" android:configchanges="keyboard|keyboardhidden|orientation|screenlayout|uimode|screensize|smallestscreensize"/> </application> </manifest>

singletop right answer. however, need implement onnewintent incoming intent not automatically set can retrieve values via getintent():

protected void onnewintent (intent intent) { setintent(intent); // rest of code can utilize getintent() before handleintent(); // should called oncreate }

android notifications

No comments:

Post a Comment