0

setRepeating()이 업데이트 APK 버전 코드setRepeating()는 알람 관리기의 바로 업데이트 APK 후, 자동으로 실행할 수있는 방법이 있나요 알람 관리기의

후 반복하지 않는 업데이트 APK 버전 코드 후 반복하지 않는 이유는 무엇입니까?
시간은 이미 이전 버전 코드에서 설정되었지만 전화가 다시 시작될 때만 알람이 작동합니다.

//SET ALARM 
Cal.setTimeInMillis(System.currentTimeMillis()); 
Cal.set(Calendar.HOUR_OF_DAY, hour); 
Cal.set(Calendar.MINUTE, minute); 
Cal.set(Calendar.SECOND, 0); 

Editor e = sharedPrefs.edit(); 
e.putLong("userTime", Cal.getTimeInMillis()); 
e.commit(); 
mytime.setSummary(DateFormat.getTimeFormat(getBaseContext()) 
     .format(new Date(Cal.getTimeInMillis()))); 

new AlarmTask(UserSettingActivity.this, Cal).run(); 

클래스 AlarmTask는 Runnable를 구현합니다

private final Calendar date; 
private final AlarmManager am; 
private final Context context; 

public AlarmTask(Context context, Calendar date) { 
    this.context = context; 
    this.am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
    this.date = date; 
} 

@Override 
public void run() { 

    Intent intent = new Intent(context, NotifyService.class); 
    intent.putExtra(NotifyService.INTENT_NOTIFY, true); 
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0); 

    am.setRepeating(AlarmManager.RTC_WAKEUP, date.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); 
} 

감사

+0

을 당신은 경보를 트리거하기 위해 사용자 지정 논리와 브로드 캐스트를 사용할 수 있습니다! – notTdar

답변

0

그냥 해결, 서비스 버전 업데이트 후 다시 시작해야합니다 많이. 매니페스트 추가

<receiver android:name=".Launcher" > 
    <intent-filter> 
     <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> 
    </intent-filter> 
</receiver> 

실행기 클래스

public class Launcher extends BroadcastReceiver { 

    public void onReceive(Context context, Intent intent) { 

     context.stopService(new Intent(context.getApplicationContext(), NotifyService.class)); 
     context.startService(new Intent(context.getApplicationContext(), NotifyService.class)); 

    } 
} 
관련 문제