Question

I have this Broadcast receiver registered

public class NotifyAlarmBroadcast extends BroadcastReceiver{
    public Context context;
    public static final String NOTI = "android.intent.action.MAIN";
// actually i want NOTI = "com.sumit.timekeeper.NotifyAlarm"
// this too is not working
// help me here please

@Override
public void onReceive(Context _context, Intent intent) {
    context = _context;
    Uri data = intent.getData();
    String reason = intent.getStringExtra("alarm_reason");
    Intent intentalarm = new Intent(NOTI, data);

    intentalarm.putExtra("reason", reason);
    context.startActivity(intentalarm);
}

}

and the manifest

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".TimeKeeperStartActivity"
        android:screenOrientation="portrait" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".NotifyAlarm"
        android:screenOrientation="portrait" android:theme="@android:style/Theme.Dialog">
        <intent-filter>
            <action android:name="com.sumit.timekeeper.NotifyAlarm">
            </action>
        </intent-filter>
    </activity>

    <receiver android:name=".NotifyAlarmBroadcast">
        <intent-filter>
            <action android:name="com.sumit.timekeeper.NotifyAlarmBroadcast" />
        </intent-filter>
    </receiver>
</application>

but when the line reaches context.startActivity(intentalarm); the application crashes

may be it is where we pass first parameter to Intent, i'm not clear about please help me.

Was it helpful?

Solution

Try to add the FLAG_ACTIVITY_NEW_TASK flag in your intent.

intentalarm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top