Reputation: 81
I Started some service from the OnReceive and When the service will end i want to get some value from that service back into the OnReceive()..
thats my code :
public class SmsListener extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
//show first message
Toast toast = Toast.makeText(context, "Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
String s=smsMessage[0].getMessageBody();
//START A SERVICE
Intent serviceIntent = new Intent(context,Lineeq.class);
serviceIntent.putExtra("message",s);
context.startService(serviceIntent);
//Here i need to get a value from the service
abortBroadcast();
}
any ideas?
Thanks.
Upvotes: 0
Views: 146
Reputation: 1007359
The BroadcastReceiver
will be gone a millisecond or two after onReceive()
returns. You cannot return a result from the service, let alone somehow block the onReceive()
method waiting for it.
Also, bear in mind that abortBroadcast()
is useless starting with Android 4.4, as you cannot abort the SMS broadcast.
Upvotes: 1