Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从通知中调用活动将强制执行新任务,从而导致;“空白”;活动_Android_Notifications - Fatal编程技术网

Android 从通知中调用活动将强制执行新任务,从而导致;“空白”;活动

Android 从通知中调用活动将强制执行新任务,从而导致;“空白”;活动,android,notifications,Android,Notifications,我有一个可能接收推送通知的应用程序。此推送通知应在用户单击时启动活动。这么标准。我让它在模拟器和Galaxy S4上工作,但Nexus设备让我头疼 起初我得到: java.lang.SecurityException: Permission Denial: start Intent 在那个特定的活动中,我通过在清单xml中的那个活动中插入android:exported=“true”来“修复”这个问题。不确定这是否是正确的方法,但我找不到更好的方法 现在我越来越紧张了 ​startActiv

我有一个可能接收推送通知的应用程序。此推送通知应在用户单击时启动活动。这么标准。我让它在模拟器和Galaxy S4上工作,但Nexus设备让我头疼

起初我得到:

java.lang.SecurityException: Permission Denial: start Intent 
在那个特定的活动中,我通过在清单xml中的那个活动中插入android:exported=“true”来“修复”这个问题。不确定这是否是正确的方法,但我找不到更好的方法

现在我越来越紧张了

​startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent 
活动已启动,但这些额外变量似乎为“null”:

导致“空”活动

以下是我在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);
到目前为止,我尝试在我的活动中插入
android:launchMode=“singleTop”
,但这似乎并没有解决问题

那么我做错了什么?为什么Nexus设备与emulator和我的Galaxy S4如此不同?在那里,我的应用程序运行良好

提前感谢您的帮助

这是我的全部舱单

<?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
是正确答案。但是,您需要实现,因为传入的
Intent
不是自动设置的,因此您可以通过
getIntent()
检索其值:


您确定这些变量不是空的吗?dataObject.getString(“oppo”)和dataObject.getString(“game”)是100%,因为我可以在日志中看到调用,并且我可以看到变量已填充,而且正如我所说,它在模拟器中的工作方式与错误“从非活动上下文调用startActivity;强制Intent.FLAG_活动_新任务:Intent这表明这里发生了一些不规范的事情。知道了。你能发布你的清单文件吗?包括我的清单:-)谢谢你的帮助,我会尽快尝试。我的代码可以在模拟器和s4上运行,但我需要为nexus设备多做一点工作,这有什么原因吗?
<?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>
protected void onNewIntent (Intent intent) {
  setIntent(intent); // now the rest of your code can use getIntent() as before
  handleIntent(); // this should also be called from onCreate as well
}