Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Java 启动完成后无法启动意图_Java_Android_Alarmmanager_Bootcompleted - Fatal编程技术网

Java 启动完成后无法启动意图

Java 启动完成后无法启动意图,java,android,alarmmanager,bootcompleted,Java,Android,Alarmmanager,Bootcompleted,我有一个关于重新安排任务的问题(带有警报)我试图在将来将任务设置为准确的时间和日期,然后关闭模拟器,然后在等待弹出布局后重新打开它,当时间和日期打开时,由于出现错误,屏幕上显示无法打开(应用程序/活动),此外,在logcat中,我看不到错误(可能应用程序已关闭),因此我不确定我到底哪里做错了什么 这是我用于服务的代码 public class ChibiReminderService extends WakefulIntentService { Date date; private long

我有一个关于重新安排任务的问题(带有警报)我试图在将来将任务设置为准确的时间和日期,然后关闭模拟器,然后在等待弹出布局后重新打开它,当时间和日期打开时,由于出现错误,屏幕上显示无法打开(应用程序/活动),此外,在logcat中,我看不到错误(可能应用程序已关闭),因此我不确定我到底哪里做错了什么

这是我用于服务的代码

public class ChibiReminderService extends WakefulIntentService {
 Date date;
 private long milliseconds = 0;
 public ChibiReminderService() {
        super("ChibiReminderService");`
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        DatabaseSched db = DatabaseSched.getInstance(this); //get access to the instance of DatabaseSched
        sched_lists alarm = new sched_lists();

        List<DatabaseSource> tasks = db.getListSched(); //Get a list of all the tasks there
        for (DatabaseSource task : tasks) {
            // Cancel existing alarm
            alarm.cancelAlarm(this, task.getId());
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm a");

             try {
                  date = format.parse(task.getDueDateTime());
                 milliseconds = date.getTime();
             } catch (Exception e) {
                 e.printStackTrace();
             }

            //regular alarms
            if(milliseconds >= System.currentTimeMillis()){
                alarm.setAlarm(this, task.getId());
            }
        }
        super.onHandleIntent(intent);
    }
}
显示

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.majimechibireminder2"
    android:versionCode="1"
    android:versionName="1.0" android:installLocation="preferExternal">

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:persistent="true">
      <receiver android:name=".OnBootReceiver" >
         <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
         </intent-filter>
     </receiver>

      <receiver android:name=".AlarmReceiver"></receiver>
       <service android:name=".ChibiReminderService" >
     </service>


您需要对丢失的数据库连接显式调用
close
,因此在
getListSched
函数末尾添加它

List<DatabaseSource> getListSched(){
.. 
..// your code 
     yourSQLiteDatabaseObject.close();
}

注意:
yourSQLiteDatabaseObject
将是
DatabaseSched
类中的
SQLiteDatabase
对象,或者如果该链不在
DatabaseSched
类中,则需要查找该链

必须在清单文件中注册你的
OnBootReceiver
?如果你的应用程序崩溃并出现错误,你肯定会得到一个logcat输出。删除所有筛选器并选择默认设置以显示每个output.post you manifest文件。是的,我将OnBootReceiver注册为receiver,将ChibiReminderService注册为服务,还添加了android.permission.RECEIVE\u BOOT\u COMPLETED还WAKE\u LOCK
List<DatabaseSource> getListSched(){
.. 
..// your code 
     yourSQLiteDatabaseObject.close();
}
 List<DatabaseSource> tasks = db.getListSched();
 db.yourSQLiteDatabaseObject.close();
        for (DatabaseSource task : tasks) {