小编Man*_*ann的帖子

通知活动崩溃

package com.example.khatrimann.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder b = new NotificationCompat.Builder(this);

    b.setTicker("khatrimann")
            .setContentTitle("Default notification")
            .setContentText("Hey There.")
            .setContentIntent(contentIntent);


    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, b.build());
}
}
Run Code Online (Sandbox Code Playgroud)

此代码在marshmallow上进行测试,它崩溃并且无法正常工作.

android.support.v4和v7,两个都是逐个尝试然后应用程序崩溃.

LOGCAT如下:

11-20 18:24:59.623 4146-4146/com.example.khatrimann.notification E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: com.example.khatrimann.notification, PID: 4146
                                                                               Theme: …
Run Code Online (Sandbox Code Playgroud)

crash android notificationmanager

0
推荐指数
1
解决办法
1384
查看次数

标签 统计

android ×1

crash ×1

notificationmanager ×1