I want to start an Intent with an AlarmManager referring to code in an inner class.
My code in MainActivity.class
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
[...]
DataProcessing2 dp = new DataProcessing2();
startstop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v1) {
if(!listening){
Log.i("Start","Button Pressed");
listening = true;
startstop.setText(R.string.stop);
dp.start(getApplicationContext());
}
}
});
}
}
My code in the DataProcessing2.class
public class DataProcessing2 {
public void start_accel(Context context){
Log.i("Start Accel","Accessed");
accel.setAccel(context);
accel.listenAccel();
Intent getAccelValuesIntent = new Intent(context, DataProcessing2.GetAccelValues.class);
PendingIntent getValues = PendingIntent.getService(context, 0, getAccelValuesIntent, 0);
getAccelData = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
getAccelData.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, System.currentTimeMillis(), sampling_acc_ms, getValues);
}
public class GetAccelValues extends IntentService {
public GetAccelValues() {
super("GetAccelValues");
}
[...]
#Override
protected void onHandleIntent(Intent intent) {
Log.i("Acc Values","Intent received");
accel.calculateAccelerometerData();
getCalculatedData();
boolean moving = sD.acc_delta > sD.acc_th;
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(NOTIFICATION_SERVICE);
broadcastIntent.putExtra("name", "answerAccelerometer");
broadcastIntent.putExtra("moving", moving);
sendBroadcast(broadcastIntent);
}
}
The problem is that I never get the receive the Intent on GetAccelValues.
The problem is that you're using incompatible clocks. You should either use AlarmManager.ELAPSED_REALTIME_WAKEUP together with System.elapsedRealtime(), or AlarmManager.RTC_WAKEUP together with System.currentTimeMillis(). For example:
getAccelData.setInexactRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), sampling_acc_ms, getValues);
Related
Receiving a notification in NotificationReceiver class that includes my data string. However, when trying to pass that string to a class in MainActivity I'm not getting any data. No errors either.
NotificationReceiver
#Override
public void onReceive(Context context, AppNotification notification) {
Toast.makeText(context, notification.payload, Toast.LENGTH_SHORT).show();
if (notification.appEvent.equals(NOTIFICATION_ACTION)) {
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra("orderId", notification.payload);
context.startActivity(intent);
}
}
MainActivity
public void onNewIntent(Intent intent) {
Toast.makeText(mContext, "Hitting New Intent", Toast.LENGTH_SHORT).show();
}
protected void onHandleIntent(Intent intent) {
Toast.makeText(getApplicationContext(), "New Order Received!", Toast.LENGTH_LONG).show();
new OrderAsyncTask().execute(intent.getStringExtra("orderId"));
}
The expected result is to receive my string in either onHandleIntent or onNewIntent
UPDATED
MainActivity Class Example:
public class MainActivity extends Activity {
public final static String EXTRA_PAYLOAD = "payload";
public String orderId = null;
#SuppressLint("StaticFieldLeak")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
onNewIntent(intent.getStringExtra("orderId"));
}
#Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
onNewIntent(intent.getStringExtra("orderId"));
}
public void onNewIntent(String orderId) {
if(orderId != null) {
Toast.makeText(MainActivity.this, "List order " + orderId, Toast.LENGTH_LONG);
} else {
Toast.makeText(MainActivity.this, "Value is null", Toast.LENGTH_LONG);
}
}
}
The methods you are trying to get the caller intent on are not overridden from anything. I suggest you to try getting the intent and processing data on activity's onCreate method
Intent intent = getIntent();
new OrderAsyncTask().execute(intent.getStringExtra("orderId"));
Also suggest you to change
public String orderId = null;
into
public String mOrderId = null;
Or just remove it because it might get mixed up with other orderId variable on your
onHandleIntent(String orderId)
method
Edit: Since you want to pass data from notification receiver to your mainActivity while the activity is running, I would suggest you to register the receiver inside your MainActivity
Please see this link, example of such design with Clover SDK https://github.com/clover/clover-android-sdk/blob/master/clover-android-sdk-examples/src/main/java/com/clover/android/sdk/examples/AppNotificationTestActivity.java
From the code:
private String orderId;
private AppNotificationReceiver receiver = new
AppNotificationReceiver() {
#Override
public void onReceive(Context context, AppNotification notification) {
log("Received " + notification);
orderId = notification.payload();
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Register the receiver to your mainActivity
receiver.register(this);
}
#Override
protected void onDestroy() {
super.onDestroy();
receiver.unregister();
}
You can directly get orderId into your MainActivity like this
Purpose of program: I'm trying to make an app that will count how many times the user checked their phone by issuing a broadcast for Intent.ACTION_SCREEN_ON. it then increments a counter and updates the activity with the new counter.
The problem: This all works just fine but as soon as I swipe away the application from the apps tray, the counter goes back to zero.
obviously what is supposed to happen is the counter would continue.
I tried saving the counter value in the service onDestroy and then calling it again onCreate but onDestroy is never called.
Note that in the onCreate() for the activity it sends a broadcast to the service asking for the most recent value of counter and then updates it in the view. I couldn't find a better way to keep them in sync.
CounterService.java
public class CounterService extends Service {
public static boolean RERUN = true;
private int counter = 0;
private SharedPreferences SP;
private BroadcastReceiver mScreenStateBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
counter++;
System.out.println("************************************* \n \n " + counter);
}
sendCounterBroadcast();
}
};
public void sendCounterBroadcast() {
Intent i = new Intent();
i.setAction("com.inc.count");
i.putExtra("counterValue", counter);
sendBroadcast(i);
}
#Override
public void onCreate() {
super.onCreate();
System.out.println("********************** CounterService.onCreate()");
// get counter value from SP -- this is useful for when the service gets recreated
SP = getSharedPreferences("Counter Service Data", MODE_PRIVATE);
counter = SP.getInt("counter", 0);
// wait for screen to be turned on or for the activity to ask you for the counter number
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction("send.counter.to.phonecounteractivity");
registerReceiver(mScreenStateBroadcastReceiver, intentFilter);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
System.out.println("***************************************** CounterService.OnDestroy()");
unregisterReceiver(mScreenStateBroadcastReceiver);
// Save counter value for when we restart service
SP = getSharedPreferences("Counter Service Data", MODE_PRIVATE);
SharedPreferences.Editor SPE = SP.edit();
if (RERUN) {
SPE.putInt("counter", counter);
System.out.println("******************************** RESTARTING SERVICE ");
startService(new Intent(getApplicationContext(), CounterService.class));
} else
SPE.putInt("counter", 0);
SPE.apply();
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
PhoneCheckerCounter.Java
public class PhoneCheckerCounter extends AppCompatActivity {
private BroadcastReceiver changeCount;
private IntentFilter filter;
private int counter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_checker_counter);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
switcherOnClick();
assignValuesOnCreate();
System.out.println("**************************** onCreate()");
changeCounterText();
}
public void switcherOnClick() {
final Switch sCounter = findViewById(R.id.switchCounter);
sCounter.setOnClickListener(new View.OnClickListener() {
Intent intent = new Intent(getApplicationContext(), CounterService.class);
#Override
public void onClick(View v) {
if (sCounter.isChecked()) {
startService(intent);
CounterService.RERUN = true;
v.getContext().registerReceiver(changeCount, filter);
Toast.makeText(getApplicationContext(), "Counting has begun", Toast.LENGTH_SHORT).show();
} else {
TextView n = findViewById(R.id.counter);
n.setText("0");
CounterService.RERUN = false;
v.getContext().unregisterReceiver(changeCount);
stopService(intent);
Toast.makeText(getApplicationContext(), "The application stopped counting", Toast.LENGTH_SHORT).show();
}
}
});
}
public void changeCounterText() {
changeCount = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
TextView n = findViewById(R.id.counter);
counter = intent.getIntExtra("counterValue", 0);
System.out.println("************************ RECEIVED!!!! value of: " + counter);
n.setText("" + counter);
}
};
filter = new IntentFilter();
filter.addAction("com.inc.count");
this.registerReceiver(changeCount, filter);
}
#Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(changeCount);
assignValuesOnDestroy();
System.out.println("**************************** onDestroy()");
}
public void assignValuesOnCreate() {
Switch s = findViewById(R.id.switchCounter);
if (getSwitchValueFromSP() == 1) s.setChecked(true);
else s.setChecked(false);
Intent f = new Intent();
f.setAction("send.counter.to.phonecounteractivity");
sendBroadcast(f);
}
public void assignValuesOnDestroy() {
SharedPreferences SP = getSharedPreferences("data", MODE_PRIVATE);
SharedPreferences.Editor edit = SP.edit();
Switch s = findViewById(R.id.switchCounter);
if (s.isChecked()) edit.putInt("switch", 1);
else edit.putInt("switch", 0);
edit.apply();
}
public int getSwitchValueFromSP() {
SharedPreferences SP = getSharedPreferences("data", MODE_PRIVATE);
int isOn = SP.getInt("switch", 0);
return isOn;
}
}
Sample of the activity
A push notification set up using alarm manager and pending intent is displaying unusual behavior. For some reason, the notification comes up a minute or less after I open up the app. Sometimes more than once a minute, then it doesn't show up for a while. My idea is to have the notification be given off once a day, assuming the user hasn't access my app in over 24hrs. I intend to cancel any previous timer, and start a new one for 1 day when the user next accesses my app. Below is my code.
public class Main_Menu extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Button goToGame1;
goToGame1 = (Button) findViewById(R.id.Game1);
goToGame1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent beAtGame1 = new Intent(Main_Menu.this, memory_modes.class);
startActivity(beAtGame1);
}
});
Button goToGame2;
goToGame2 = (Button) findViewById(R.id.Game2);
goToGame2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent beAtGame2 = new Intent(Main_Menu.this, computation_modes.class);
startActivity(beAtGame2);
}
});
Button goToGame3;
goToGame3 = (Button) findViewById(R.id.Game3);
goToGame3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent beAtGame3 = new Intent(Main_Menu.this, evaluation_modes.class);
startActivity(beAtGame3);
}
});
Button goToGame4;
goToGame4 = (Button) findViewById(R.id.Game4);
goToGame4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent beAtGame4 = new Intent(Main_Menu.this, attention_modes.class);
startActivity(beAtGame4);
}
});
Button goToTrackers;
goToTrackers = (Button) findViewById(R.id.Trackers);
goToTrackers.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent beAtTrackers = new Intent(Main_Menu.this,trackerMenu.class);
startActivity(beAtTrackers);
}
});
Intent intent = new Intent(Main_Menu.this, Receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Main_Menu.this, 1, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
alarm.cancel(pendingIntent);
alarm.setRepeating(alarm.RTC_WAKEUP, System.currentTimeMillis(), alarm.INTERVAL_DAY, pendingIntent);
}
public void onBackPressed() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
and
public class Receiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
showNotification(context);
}
public void showNotification(Context context) {
Intent intent = new Intent(context, Main_Menu.class);
PendingIntent pi = PendingIntent.getActivity(context, 1, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.smalliconfinal)
.setColor(Color.argb(000,255,177,17))
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon4))
.setContentTitle("Title")
.setContentText("Some text.");
mBuilder.setLights(0xffffb111, 750, 750);
mBuilder.setContentIntent(pi);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
and from my Manifest:
<receiver android:name=".Receiver"></receiver>
Anyone know why this issue occurs?
Much appreciated,
thank you.
The second parameter to the AlarmManager.setRepeating method is the time the alarm should first go off.
You're calling this method using these parameters:
alarm.setRepeating(alarm.RTC_WAKEUP, System.currentTimeMillis(), alarm.INTERVAL_DAY, pendingIntent);
Which means that you're setting the repeating alarm to go off as soon as you call the method (when the Main_Menu activity is created).
From your description it seems like you're looking for something like this:
alarm.setRepeating(AlarmManager.RTC_WAKEUP, (System.currentTimeMillis() + AlarmManager.INTERVAL_DAY), AlarmManager.INTERVAL_DAY, pendingIntent);
Here's code for a timer that plays a sound once it reaches 0 (timer works fine). The problem is the sound persists even through onPause() in MainActivity.java called.
I implemented onDestroy() in SimpleIntentService.java to stop the sound, but apparently it's never called even with finish() in the calling Activity. How am I supposed to make the sound stop when the app is paused?
Here's my MainActivity.java
public class MainActivity extends Activity {
private BroadcastReceiver broadcastReceiver;
NumberPicker picker;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
picker = (NumberPicker) findViewById(minutePicker);
Log.i("TurnToTech", "Project Name - SimpleBackgroundService");
picker.setMinValue(0);
picker.setMaxValue(20);
broadcastReceiver = new BroadcastReceiver(){
#Override
public void onReceive(Context arg0, Intent intent) {
String text = intent.getStringExtra(SimpleIntentService.PARAM_OUT_MSG);
Toast.makeText(getApplicationContext(),
text, Toast.LENGTH_SHORT).show();
}
};
}
Intent msgIntent;
public void startTimer(View view) {
setContentView(R.layout.activity_main);
msgIntent = new Intent(this, SimpleIntentService.class);
msgIntent.putExtra(SimpleIntentService.PARAM_IN_MSG, "Alarm: ");
msgIntent.putExtra("time", picker.getValue());
startService(msgIntent);
}
public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter(SimpleIntentService.ACTION_RESP);
filter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(broadcastReceiver,filter);
}
public void onPause() {
finish();
unregisterReceiver(broadcastReceiver);
super.onPause();
}
}
And the SimpleIntentService.java
public class SimpleIntentService extends IntentService {
public static final String PARAM_IN_MSG = "in_msg";
public static final String PARAM_OUT_MSG = "out_msg";
int time;
public static final String ACTION_RESP = "org.turntotech.intent.action.MESSAGE_PROCESSED";
public SimpleIntentService() {
super("SimpleIntentService");
}
#Override
protected void onHandleIntent(Intent intent) {
System.out.println("SimpleIntentService Called");
String msg = intent.getStringExtra(PARAM_IN_MSG);
int time = intent.getIntExtra("time", 0);
// Timer implementation
if (time == 0 ){
playSound();
}
while(time > 0){
SystemClock.sleep(5000); // 5 seconds
time -= 5;
String resultTxt = msg + time + " seconds remaining";
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(ACTION_RESP);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
broadcastIntent.putExtra(PARAM_OUT_MSG, resultTxt);
broadcastIntent.putExtra("time", time);
sendBroadcast(broadcastIntent);
if (time == 0) {
playSound();
}
}
}
Uri alert;
public void playSound(){
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert);
r.play();
}
public void onDestroy() {
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert);
r.stop();
super.onDestroy();
}
}
In your IntentService you're not really stopping the same alarm in your onDestroy function. Because each time you're getting a new instance of it.
So I would like to suggest to keep a public static variable of Ringtone so that it can be accessed from everywhere. Declare them in your MainActivity.
public static Ringtone r;
public static Uri alert;
Initialize them in the onCreate function of your MainActivity.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ... Other statements
// Initialize ringtone here
initializeRingtone();
}
private void initializeRingtone() {
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
r = RingtoneManager.getRingtone(getApplicationContext(), alert);
}
Now the onPause() function of your MainActivity should look like this
public void onPause() {
unregisterReceiver(broadcastReceiver);
r.stop();
super.onPause();
}
And if you want to play the sound after you resume the application from background and then the timer runs out, you might consider doing something like this in the onResume function of your MainActivity
public void onResume() {
super.onResume();
registerReceiver(broadcastReceiver);
initializeRingtone(); // Initialize it again.
}
And the playSound() function in the IntentService might look like this.
public void playSound(){
// Initialize the alert and ringtone again.
MainActivity.alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
MainActivity.r = RingtoneManager.getRingtone(getApplicationContext(), alert);
MainActivity.r.play();
}
public void onDestroy() {
MainActivity.r.stop();
super.onDestroy();
}
Hope that helps!
I have an android application where I'm using GCM. I'm following the tutorials and using an InstanceIDListenerService class which I'm attempting to fire off as an IntentService after a "subscription" page where the user enters some information. There is also some preliminary code firing off prior to this subscription page on a splash screen behind the scenes. The InstanceIDListenerService constructor is being called (and subsequently, the onHandleIntent) in the SplashScreen activity before I even get to the SubscriptionActivity. Why is it doing this? Is it possible for an intent service to start on it's own?
I do have the service registered in the AndroidManifest.xml file, and when I comment out the following lines, it does not trigger the instance to get created automatically, the app works as intended (until I need to use the instance of course...)
<service
android:name=".service.receiver.InstanceIDListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
SplashScreen.java
public class SplashScreen extends Activity {
private BroadcastReceiver dbInsertReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(bundle != null) {
// Handle results and move to next activity, should
// be the subscribe activity where I want the instance
// id listener to start.
}
}
};
private BroadcastReceiver providerXMLReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(bundle != null) {
// Handle results and start the next service
}
}
}
};
/** Called when the activity is first created */
#Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_splash_screen);
// Kick off the service download to update the provider data
Intent intent = new Intent(this, ProviderDataService.class);
startService(intent);
}
#Override
protected void onStart() {
super.onStart();
registerReceiver(providerXMLReceiver, new IntentFilter(ProviderDataService.CHANNEL));
registerReceiver(dbInsertReceiver, new IntentFilter(InternalDBService.NOTIFICATION));
}
#Override
protected void onResume() {
super.onResume();
registerReceiver(providerXMLReceiver, new IntentFilter(ProviderDataService.CHANNEL));
registerReceiver(dbInsertReceiver, new IntentFilter(InternalDBService.NOTIFICATION));
}
#Override
protected void onPause() {
super.onPause();
unregisterReceiver(providerXMLReceiver);
unregisterReceiver(dbInsertReceiver);
}
private void moveToNextActivity(int subscriptionStatus) {
if(subscriptionStatus == DBSchemaHelper.IS_SUBSCRIBED_NOT_RESPONDED) {
Intent subscribeIntent = new Intent(SplashScreen.this, SubscribeActivity.class);
startActivity(subscribeIntent);
} else {
// Create an Intent that will start the Menu-Activity.
Intent mainIntent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(mainIntent);
}
this.finish();
}
SubscribeActivity.java
public class SubscribeActivity extends CustomActionBarActivity {
public static final int NO_SUBSCRIPTION_STATUS = -99;
private DBMetaDataSource metaDao;
private int subscribeResult;
public SubscribeActivity() {
metaDao = new DBMetaDataSource(this);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subscribe);
}
#Override
protected void onStart() {
super.onStart();
registerReceiver(tokenResponseReceiver, new IntentFilter(InstanceIDListenerService.TAG));
}
#Override
protected void onResume() {
super.onResume();
registerReceiver(tokenResponseReceiver, new IntentFilter(InstanceIDListenerService.TAG));
}
#Override
protected void onPause() {
super.onPause();
unregisterReceiver(tokenResponseReceiver);
}
public void subscribeUser(View v) {
EditText emailTextView = (EditText) findViewById(R.id.subscriptionUserEmail);
String email = emailTextView.getText().toString();
// This is the only place I am manually starting this service.
// I have set a breakpoint here, but I never hit it and the service
// starts on its own and I hit the breakpoints in the service's
// onHandleIntent method.
Intent i = new Intent(this, InstanceIDListenerService.class);
i.putExtra("email", email);
startService(i);
}
public void goToNextActivity(View v) {
// They pressed the button to NOT subscribe, so we are calling this from the
// view rather than the intent receiver, meaning the view will not be null.
if(v != null) {
markUnsubscribed();
}
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(SubscribeActivity.this, MainActivity.class);
mainIntent.putExtra(MainActivity.SUBSCRIBE_STATUS_KEY, subscribeResult);
startActivity(mainIntent);
}
private void markUnsubscribed() {
metaDao.open(this);
DBMeta metaData = metaDao.get();
metaDao.update(Long.valueOf(metaData.getVersion()), metaData.getLastRunInMillis(), DBSchemaHelper.IS_SUBSCRIBED_RESPONDED_NO, null);
metaDao.close();
}
private BroadcastReceiver tokenResponseReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
subscribeResult = intent.getIntExtra(InstanceIDListenerService.RESPONSE_KEY, NO_SUBSCRIPTION_STATUS);
goToNextActivity(null);
}
};
}
You shouldn't be starting a InstanceIDListenerService yourself - that is for the system to call you when you need to refresh your Instance ID tokens via a callback to onTokenRefresh() - if you haven't created any instance id tokens yet, then you'd just have no work to do on that first call.
If you have other work to do, you should use your own service.