Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/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
Android Intentservice工作不正常_Android_Sqlite_Intentservice - Fatal编程技术网

Android Intentservice工作不正常

Android Intentservice工作不正常,android,sqlite,intentservice,Android,Sqlite,Intentservice,我有一个活动,用户选择日期和时间,然后将日期输入sqlite数据库。从这个活动中,我开始了下面这样的IntentService Intent intents = new Intent (this,AlarmIntentService.class); startService(intents); 在intentservice中,我将sqlite数据库中的数据与当前系统时间进行比较,并广播警报 当我第一次调用intentservice时,它工作得很好,只需在数据库中输入一个条目。但是,当用

我有一个活动,用户选择日期和时间,然后将日期输入sqlite数据库。从这个活动中,我开始了下面这样的IntentService

Intent intents = new Intent (this,AlarmIntentService.class);
    startService(intents);
在intentservice中,我将sqlite数据库中的数据与当前系统时间进行比较,并广播警报

当我第一次调用intentservice时,它工作得很好,只需在数据库中输入一个条目。但是,当用户将第二个数据插入sqlite数据库并启动Intentservice时,它就不起作用了

是否仍要使用新数据更新传递的intentservice

intentservice OnHandle内容描述如下

 final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    final SqliteController db = new SqliteController(getApplicationContext());
    List<Greetings> greetings = db.getAllGreetings();
    int k = db.getGreetingsCount();
    String p = String.valueOf(k);
    Log.d("p", p);    
if (db.getGreetingsCount() >= 0) {
        do {
            for (Greetings g : greetings) {
                Calendar cal = Calendar.getInstance();
                d1 = cal.get(Calendar.DAY_OF_MONTH);
                d2 = cal.get(Calendar.MONTH);
                d3 = cal.get(Calendar.YEAR);
                t1 = cal.get(Calendar.HOUR);
                t2 = cal.get(Calendar.MINUTE);
                t3 = cal.get(Calendar.AM_PM);
                if (t3 == 1) {
                    t4 = "PM";
                } else {
                    t4 = "AM";
                }

                tc = String.valueOf(t1) + " : " + t2 + " " + t4;

                d = String.valueOf(d3) + "-" + String.valueOf(d2 + 1) + "-" + String.valueOf(d1);
                cdt = d + "\t" + tc;
                time = g.getTime();
                date = g.getDate();
                phone = g.getPhoneNumber();
                msg = g.getMessage();
                id = g.getID();
                dnt = date + "\t" + time;

                if (dnt.equals(cdt)) {
                    Intent aint = new Intent(getApplicationContext(), AlarmReceiver.class);

                    aint.putExtra("msg", msg);
                    aint.putExtra("phone", phone);
                    aint.putExtra("id", id);
                    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), id, aint, PendingIntent.FLAG_UPDATE_CURRENT);
                    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
                    showNotification();
                    db.deleteGreetings(g);
                }

            }
            k = db.getGreetingsCount();

        } while (k != 0);
final AlarmManager AlarmManager=(AlarmManager)getSystemService(Context.ALARM_服务);
最终SqliteController db=新的SqliteController(getApplicationContext());
列表问候语=db.getAllGreetings();
int k=db.getGreetingScont();
字符串p=字符串。值(k);
对数d(“p”,p);
如果(db.getGreetingScont()>=0){
做{
问候语(g:问候语){
Calendar cal=Calendar.getInstance();
d1=cal.get(日历日/月日);
d2=计算日期(日历月);
d3=校准日期(日历年);
t1=计算时间(日历小时);
t2=校准获取(日历分钟);
t3=校准获取(日历上午/下午);
如果(t3==1){
t4=“PM”;
}否则{
t4=“AM”;
}
tc=字符串。值(t1)+“:“+t2+”+t4;
d=字符串.valueOf(d3)+“-”字符串.valueOf(d2+1)+“-”字符串.valueOf(d1);
cdt=d+“\t”+tc;
时间=g.getTime();
日期=g.getDate();
phone=g.getPhoneNumber();
msg=g.getMessage();
id=g.getID();
dnt=日期+“\t”+时间;
如果(dnt等于(cdt)){
Intent aint=新的Intent(getApplicationContext(),AlarmReceiver.class);
无额外费用(“味精”,味精);
不含额外费用(“电话”,电话);
无额外费用(“id”,id);
PendingEvent PendingEvent=PendingEvent.getBroadcast(getApplicationContext(),id,aint,PendingEvent.FLAG_UPDATE_CURRENT);
alarmManager.set(alarmManager.RTC_WAKEUP,cal.getTimeInMillis(),PendingContent);
showNotification();
db.1(g);
}
}
k=db.getGreetingScont();
}而(k!=0);

您可以使用意向过滤器为您的服务呼叫使用以下代码


尝试将所有声明移出循环。这对我很有效。

1:创建文件类:

public class ClassAlarm extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent)
    {
       Log.i("BroadCast Alarm", "do anything");         
    }
}
<receiver android:name=".ClassAlarm" >
    <intent-filter>
         <action android:name="broadCastAlarm" />
    </intent-filter>
</receiver>
2º在ANDROIDMANIFEST文件中注册您的广播:

public class ClassAlarm extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent)
    {
       Log.i("BroadCast Alarm", "do anything");         
    }
}
<receiver android:name=".ClassAlarm" >
    <intent-filter>
         <action android:name="broadCastAlarm" />
    </intent-filter>
</receiver>