【问题标题】:how to make the onreboot service work in a better way如何使 onreboot 服务以更好的方式工作
【发布时间】:2013-12-28 15:24:36
【问题描述】:

我有一个必须在重启后才能工作的代码;这是一项服务,它将重新创建我在设备关闭之前曾经拥有的警报......

我的代码是:

 public void onReceive(Context context, Intent intent) {        
         c=context;
        sp= PreferenceManager.getDefaultSharedPreferences(context);
        sp.edit().putInt("CheckeForConnectionNumber", 0).commit();
        Toast.makeText(c,"checknumber= "+sp.getInt("CheckeForConnectionNumber", 

0), Toast.LENGTH_LONG).show();

    bool_activate_reminder=sp.getBoolean("reminder_on_off", false);

     if(bool_activate_reminder==true){           

         //if I start it on the reboot it will take wrong info and return wrong hours..

                      Intent inte = new Intent(c,AlarmService.class);
                         c.startService(inte);

                }

所以它正在调用一个服务,该服务将在设备重新启动后重新创建警报 并创建我需要获取位置的警报;它运行良好,但有时该位置被视为 0.0,因为设备没有足够的时间来检索它; 我创建了一个线程,该线程会在一段时间后启动服务,但它没有按需要工作......那我该怎么办?

【问题讨论】:

    标签: android service location reboot


    【解决方案1】:

    我做了什么:

    OnBootReceiver 我创建了一个警报,它在一分钟后响起,并在关闭时调用服务; 这样该位置以正确的方式获取并且没有

    latitude=0.0
    longitude=0.0
    

    有问题了……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-07
      • 2021-02-20
      • 1970-01-01
      相关资源
      最近更新 更多