firebase android和广播接收器

mpgws1up  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(275)

我使用setinexactrepeating将alarm manager设置为每天三次有三个通知。
既然我在这里找不到答案,我就来问。我正在从广播接收器内的firebase数据库中获取用户的存储图像和用户名,广播接收器位于alarm manager中使用的pendingintent内,带有字符串附加项,如用户id等。现在的问题是,当应用程序被关闭时,intent extra是否会存储在alarm manager中使用的pendingent中,而当应用程序被关闭时,广播接收器是否仍能访问数据库。如果不是,我该怎么解决?
下面是我在receiver中获取用户id的代码:

String selection = intent.getStringExtra("selection");
    String selected_user = intent.getStringExtra("selected_id");
    String unique_id = intent.getStringExtra("unique_id");
    String current_user_id = intent.getStringExtra("current_id");

    mMyGroupRef = FirebaseDatabase.getInstance().getReference().child("My Group").child(current_user_id).child(selection);

    mOtherUserMyGroupRef = FirebaseDatabase.getInstance().getReference().child("My Group").child(selected_user);

    mMyGroupRef.addListenerForSingleValueEvent(new ValueEventListener() { //etc...

报警管理器(我已将mscheduletask设置为静态变量,在oncreate中初始化为mscheduletask=(alarmmanager)objects.requirennoull(getcontext()).getsystemservice(context.alarm_service);)电话:

calendar1 = Calendar.getInstance();
            calendar1.setTimeInMillis(System.currentTimeMillis());
            calendar1.set(Calendar.HOUR_OF_DAY, 8);
            calendar2 = Calendar.getInstance();
            calendar2.setTimeInMillis(System.currentTimeMillis());
            calendar2.set(Calendar.HOUR_OF_DAY, 14);
            calendar3 = Calendar.getInstance();
            calendar3.setTimeInMillis(System.currentTimeMillis());
            calendar3.set(Calendar.HOUR_OF_DAY, 18);

            Intent intent = new Intent(getContext(), AutoMessageReceiver.class);
            intent.putExtra("unique_id", "" + uniqueID);
            intent.putExtra("selection", selection);
            intent.putExtra("selected_id", user_id);
            intent.putExtra("current_id", currentID);
            PendingIntent pendingIntent1 = PendingIntent.getBroadcast(getContext(), uniqueID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent pendingIntent2 = PendingIntent.getBroadcast(getContext(), uniqueID - 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent pendingIntent3 = PendingIntent.getBroadcast(getContext(), uniqueID - 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);

            mScheduleTask.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent1);
            mScheduleTask.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar2.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent2);
            mScheduleTask.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar3.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent3);

然后我检查数据库中是否存在这种情况,我称之为shownotification方法,它采用用户名和毕加索图书馆中使用的图像链接。
当我启动应用程序并选择我希望一天关闭三次通知的用户时,一切正常。我确实收到了,但有时发生的是

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题