onReceive method doesn't get called

前端 未结 1 1707
暖寄归人
暖寄归人 2020-12-02 02:25
public class BroadcastTest extends Activity {
BroadcastReceiver receiver;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle s         


        
相关标签:
1条回答
  • 2020-12-02 02:59

    This Blog post describes some common pitfalls with AlarmManager and BroadcastReceiver. Examples included! Hope that helps.

    EDIT: Some common pitfalls:

    1. Receiver not declared in AndroidManifest.xml

      Declare the receiver in the Manifest-file:

      <receiver android:name="net.fusonic.testapp.receivers.TestAlarmReceiver"></receiver>
      
    2. Receiver in the Manifest xml is misspelled

      Always remember that the whole Android-System is case sensitive. So check your spelling is correct in the AndroidMainfest.xml. Remember that the eclipse refactoring functions do not change packagename correctly if you use the short form like “.receivers.TestAlarmReceiver“.

    3. PendingIntent requestCode missing?

      If you create a PendingIntent for your Receiver, please add a requestCode – even it is a random number! Without your “onReceive” code never get called!

    4. AVD running for a long time (very tricky)

      Be aware of using the AVDs especially if your working with “REALTIME_WAKEUP” and SystemClock… So if you try to test your alarm, please restart the AVD or test on a real device!

    0 讨论(0)
提交回复
热议问题