public class RegistrationIntentService extends JobIntentService {
private static final String TAG = "RegIntentService";
private static final String[] TOPICS = {"global"};
private static Context context1;
private String SENDER_ID;
private AppActivity appActivityContext;
private SharedPreferences.Editor editor;
public RegistrationIntentService() {
super();
}
@Override
protected void onHandleWork(@NonNull Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
// [END register_for_gcm]
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
}
// Notify UI that registration has completed, so the progress indicator can be hidden.
Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
...
}
我实现了jobintentservice但它不起作用。只调用默认构造函数中的super()。不调用OnHandleWork 在8以下的Android版本上正常工作