Ich habe einen Benachrichtigungsmanager in einem Fragment, es funktioniert gut, bis Sie darauf klicken, wo es Fragmentierung_02-Klasse öffnen soll, wo es geklickt wird (be es aus dem Home-Bildschirm, ein weiteres Fragment oder Aktivität)Fragment kann nicht in eine android.app.activity on Notification umgewandelt werden Klicken Sie auf
Code unten:
private void pushNotification(int Request_ContactIntTotal) {
NotificationManager NM = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
if (Request_ContactIntTotal == 0)
{
NM.cancelAll();
}
else
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity());
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("Message Notification");
uilder.setContentText(Request_ContactIntTotal + " unread messages");
Intent intent = new Intent(getActivity(),Fragment_02.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(getActivity());
stackBuilder.addParentStack(Fragment_02.class);
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
NM.notify(0,builder.build());
}
}
Benachrichtigung Klick gibt Fehler: Fragment_02 kann nicht in den Android App-Aktivitäten gegossen werden
Logcat:
08-01 21:04:49.499: E/AndroidRuntime(3596): FATAL EXCEPTION: main
08-01 21:04:49.499: E/AndroidRuntime(3596): Process: com.mypackage.myapp, PID: 3596
08-01 21:04:49.499: E/AndroidRuntime(3596): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mypackage.myapp/com.mypackage.myapp.Fragment_02}: java.lang.ClassCastException: com.mypackage.myapp.Fragment_02 cannot be cast to android.app.Activity
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.app.ActivityThread.access$800(ActivityThread.java:144)
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.os.Handler.dispatchMessage(Handler.java:102)
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.os.Looper.loop(Looper.java:135)
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.app.ActivityThread.main(ActivityThread.java:5221)
08-01 21:04:49.499: E/AndroidRuntime(3596): at java.lang.reflect.Method.invoke(Native Method)
08-01 21:04:49.499: E/AndroidRuntime(3596): at java.lang.reflect.Method.invoke(Method.java:372)
08-01 21:04:49.499: E/AndroidRuntime(3596): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
08-01 21:04:49.499: E/AndroidRuntime(3596): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
08-01 21:04:49.499: E/AndroidRuntime(3596): Caused by: java.lang.ClassCastException: com.mypackage.myapp.Fragment_02 cannot be cast to android.app.Activity
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
08-01 21:04:49.499: E/AndroidRuntime(3596): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
Aktualisieren Sie Ihre Frage wird abgeschlossen LogCat. – Sufian
Mögliches Duplikat von [Fragment kann nicht in eine android.app.activity umgewandelt werden] (http://stackoverflow.com/questions/22705146/fragment-cannot-becast-to-an-android-app-activity) – Sufian