对象不是在notify()之前被线程锁定的吗?

时间:2018-09-08 19:19:22

标签: java android

我正在尝试解决该问题,但失败了,我看到了其他堆栈溢出的问题,但未能解决

如何解决以下问题?

  

notificationBuilder.notify(notiID,notificationBuilder.build());

public class Noti extends AppCompatActivity {

NotificationManager notificationManager;
Boolean isNotiActive=false;
int notiID=33;
NotificationCompat.Builder notificationBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_noti);

   notificationBuilder= new NotificationCompat.Builder(this)
            .setContentTitle("Alert")
            .setContentText("new msg")
            .setTicker("Alert new msg");

    Intent intent=new Intent(Noti.this, MoreNoti.class);

    TaskStackBuilder stackBuilder= TaskStackBuilder.create(this);
    stackBuilder.addParentStack(Noti.class);
    stackBuilder.addNextIntent(intent);

    PendingIntent pendingIntent=stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    notificationBuilder.setContentIntent(pendingIntent);

     notificationBuilder.notify(notiID , notificationBuilder.build());

     isNotiActive=true;

}

}

1 个答案:

答案 0 :(得分:1)

您没有使用正确的notify()

更改

notificationBuilder.notify(notiID, notificationBuilder.build());

notificationManager.notify(notiID, notificationBuilder.build());

Object#notify()是Java中用于处理多线程的方法。那不是你想要的。