How to use PendingIntent on BroadcastReceiver
-
01-07-2021 - |
Question
I am trying to set up a message application such that:
- First we set up a message on PreferenceConnector and we receive the message then
- BroadcastReceiver checks that the message contents are equal then
- I want to get a PendingIntent.
try { if (PreferenceConnector.readString(context,"MSG","tempmsg2").equals(messages[0].getMessageBody())) { Intent i=new Intent(context, SecureMobiActivity.class); PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0); } else { Toast.makeText(Remotelock.this, "message are not equal!", Toast.LENGTH_LONG).show(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); }
Solution
its answer is so simple
try {
if (PreferenceConnector.readString(context,"MSG","tempmsg2").equals(messages[0].getMessageBody())) {
Intent i = new Intent(mContext,SecureMobiActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(i);
} else {
Toast.makeText(Remotelock.this, "message are not equal!", Toast.LENGTH_LONG).show();
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow