简体   繁体   English

Android BOOT_COMPLETED成功运行Service,但同时也打开了该应用

[英]Android BOOT_COMPLETED runs Service successfully but it opens the app too

In my application, I've alarm feature set on multiple time. 在我的应用程序中,我将警报功能设置为多次。 So after device restart/start, I'm fetching alarm data from DB and set alarm again using Service. 因此,在设备重新启动/启动之后,我将从数据库中获取警报数据,然后使用服务再次设置警报。 This works fine but after setting the alarm (I printed on log), app open as well. 这可以正常工作,但是在设置警报(我在日志上打印)后,应用也将打开。 But I'm not starting any activity from that Service. 但是我没有从该服务开始任何活动。 Please have a look at the Service class code below: 请查看下面的服务类代码:

public void onCreate() {
    super.onCreate();

    DBHelper moodsDB = new DBHelper(this);

    ArrayList<HashMap<String, String>> reminder_list = moodsDB.getAllReminders();

    for (HashMap<String, String> reminder : reminder_list) {
        if(Integer.parseInt(reminder.get("active").toString()) == 1){
            Date time = Utility.stringToDate(reminder.get("time").toString(), Utility.TIME_FORMAT_APP);
            Log.i("Mood Journal", "Reminder Time = " + Utility.dateToString(time, Utility.TIME_FORMAT_APP));

            Utility.cancelAlarmIfExists(this, Integer.parseInt(reminder.get("id").toString()));

            Utility.setAlarm(this, 
                    Integer.parseInt(reminder.get("id").toString()),
                    time.getTime());
        }
    }
}

What could be reason and how to solve this flaw, please suggest. 请提出可能是什么原因以及如何解决此缺陷。

long now = new Date().getTime(); 
while (time < now) { 
    time += AlarmManager.INTERVAL_DAY; 
}

I need to add the above code snippet before setting alarm to prevent app to open after device reboot. 我需要在设置警报之前添加以上代码段,以防止设备重启后打开应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM