内部方法中的Android通知无效

时间:2014-11-18 21:13:19

标签: android android-notifications

除了 onCreate(Bundle savedInstanceState )之外,从程序中的其他区域调用 MakeNotification() 时,我的代码无效 方法,只有通知正常。

请帮助; - )

public void MakeNotification() {
    // notify
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setAutoCancel(true)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Tie")
                    .setContentText("Clipboard cleared");

    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(1212, mBuilder.build());
}

I.E:尝试从此处拨打 MakeNotification()

    public void delayedClearTextview(final Handler handler, final TextView txt) {
    Timer timer = new Timer();
    TimerTask delayedTask = new TimerTask() {
        @Override
        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    txt.setText(R.string.opt); 
                    MakeNotification() // <<<<<----- WILL NOT WORK !!!! <<<<
                }
            });
        }
    };
    timer.schedule(delayedTask, (1000));

编辑:唯一的问题是从另一个方法调用MakeNotification()方法时没有显示通知。我在这里错过了什么吗? :()

0 个答案:

没有答案