Broadcastreceiver Not Sending Back Data To Main Class
I am using a BroadcastReceiver to set up an alarm alaret and for some reason it won't work. public class SimpleSleepActivity extends Activity { /** Called when the activity is fir
Solution 1:
More likely, you forgot to add the BroadCast Receiver to your AndroidManifest.xml To be able to use it, it must be declared in your manifest:
<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"package="com.yourpackage.name"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="9" /><uses-permissionandroid:name="com.android.alarm.permission.SET_ALARM"/><applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name" ><!-- Your activity here --><activityandroid:name="SimpleSleepActivity"><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter></activity><!-- Your Receiver here --><receiverandroid:name="AlarmFromNow"></receiver></application></manifest>
NOTE: I quickly tested your code, with this manifest, and indeed it shows the Toast after 10 secs...
Solution 2:
I ran into something similar to this. I had to set an action on the Intent
to get it to work properly. The value passed in with setAction()
didn't matter. Try...
Intentintent=newIntent(SimpleSleepActivity.this,
AlarmFromNow.class);
intent.setAction("Doesn't Really Matter");
PendingIntentsender= PendingIntent.getBroadcast(
SimpleSleepActivity.this, 0, intent, 0);
Post a Comment for "Broadcastreceiver Not Sending Back Data To Main Class"