Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 打开“正在进行的通知”时,通知栏会滞后_Android_Broadcastreceiver_Android Preferences_Android Notifications_Batterylevel - Fatal编程技术网

Android 打开“正在进行的通知”时,通知栏会滞后

Android 打开“正在进行的通知”时,通知栏会滞后,android,broadcastreceiver,android-preferences,android-notifications,batterylevel,Android,Broadcastreceiver,Android Preferences,Android Notifications,Batterylevel,我的应用程序在通知栏中有一个通知,显示电池电量。通知可以工作,但是当首选项中的复选框被单击并且通知出现时,我试图拉下通知栏,但它会延迟。我不知道怎么办,但我认为这是因为通知每秒都会检查电池电量,但我不确定。。我发布代码: @SuppressLint("NewApi") private void checkPref(Intent intent){ this.registerReceiver(this.batteryInfoReceiver, new IntentF

我的应用程序在通知栏中有一个通知,显示电池电量。通知可以工作,但是当首选项中的复选框被单击并且通知出现时,我试图拉下通知栏,但它会延迟。我不知道怎么办,但我认为这是因为通知每秒都会检查电池电量,但我不确定。。我发布代码:

@SuppressLint("NewApi")
    private void checkPref(Intent intent){ 
            this.registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
            SharedPreferences myPref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); 
            boolean pref_opt1 = myPref.getBoolean("firstDependent", false); 
            int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
            if (pref_opt1){
                NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                 Notification notification = new Notification.Builder(getApplicationContext())
                 .setContentTitle("Battery Informations")
                 .setContentText("Battery level"+" "+level+"%")
                 .setSmallIcon(R.drawable.icon_small_not)
                 //.setLargeIcon(aBitmap)
                 .setTicker(level+"%")
                 .build();

                 notification.flags = Notification.FLAG_ONGOING_EVENT;
                 Intent i = new Intent(MainActivity.this, MainActivity.class); 
                 PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
                 notifi.notify(215,notification);
                } else {
                NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                notifi.cancel(215);
                }
        }

问题可能是这个
this.registerReceiver(this.batteryForeceiver,新的IntentFilter(Intent.ACTION\u BATTERY\u CHANGED))。但我只知道在电池电量变化时更新通知的方法。。请提供一些帮助?

检查显示通知的“if case”代码是否重复执行。如果是这样,请尝试通过标志值将显示通知限制为一次,并在notifi.cancel()期间重置标志