我已经开发了一个应用程序并实现了GCM(Google云消息传递),它在模拟器和蓝色堆栈上运行得非常好,但是当我在设备上运行时,它很快就停止了,我无法理解。< / p>
Manifest file
<uses-sdk android:minSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.androiddemos.NotificationActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".ResultActivity"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".NotificationActivity" />
</activity>
<activity
android:name=".GcmActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.google.android.gcm.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.example.androiddemos" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" >
</service>
</application>
<permission
android:name="com.example.androiddemos.permission.C2D_MESSAGE"
android:protectionLevel="signature" >
</permission>
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.example.androiddemos.permission.C2D_MESSAGE" />
logcat的
01-09 14:55:27.034: E/AndroidRuntime(25344): java.lang.IllegalArgumentException: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{com.example.androiddemos/com.example.androiddemos.MainActivity}
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:236)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:215)
01-09 14:55:27.034: E/AndroidRuntime(25344): at com.example.androiddemos.GcmActivity.sendNotification(GcmActivity.java:70)
01-09 14:55:27.034: E/AndroidRuntime(25344): at com.example.androiddemos.GcmActivity.checkGCM(GcmActivity.java:49)
01-09 14:55:27.034: E/AndroidRuntime(25344): at com.example.androiddemos.GcmActivity$1.onClick(GcmActivity.java:33)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.view.View.performClick(View.java:4084)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.view.View$PerformClick.run(View.java:16966)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.os.Handler.handleCallback(Handler.java:615)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.os.Handler.dispatchMessage(Handler.java:92)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.os.Looper.loop(Looper.java:137)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 14:55:27.034: E/AndroidRuntime(25344): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 14:55:27.034: E/AndroidRuntime(25344): at java.lang.reflect.Method.invoke(Method.java:511)
01-09 14:55:27.034: E/AndroidRuntime(25344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 14:55:27.034: E/AndroidRuntime(25344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 14:55:27.034: E/AndroidRuntime(25344): at dalvik.system.NativeStart.main(Native Method)
01-09 14:55:27.034: E/AndroidRuntime(25344): Caused by: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{com.example.androiddemos/com.example.androiddemos.MainActivity}
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:225)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:298)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.NavUtils.getParentActivityIntent(NavUtils.java:261)
01-09 14:55:27.034: E/AndroidRuntime(25344): at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:229)
01-09 14:55:27.034: E/AndroidRuntime(25344): ... 15 more
答案 0 :(得分:3)
我认为问题是因为您没有在清单中根据此logcat行定义MainActivity:
14:55:27.034: E/AndroidRuntime(25344): Caused by:
android.content.pm.PackageManager$NameNotFoundException:
ComponentInfo{com.example.androiddemos/com.example.androiddemos.MainActivity} 01-09
您将MainActivity引用为parentActivityName,但未在清单中定义:
<activity
android:name=".ResultActivity"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".NotificationActivity" />
</activity>
如果您仍在使用MainActivity,则需要将其添加到清单中:
<activity
android:name=".MainActivity">
</activity>