Hi,
I am trying to create an AlertDialog at the advent of an SMS. I have
created an SMSReceiver class and registered it for SMS_RECEIVED intent
in the Android.manifest file. From inside the onReceive method of this
class, I invoke another Activity which creates a dialog box.
I am able to create a AlertDialog once but when I receive second
message the AlertDialog doesn't get updated. Infact
SMSNotificationActivity (described below) doesn't get started second
time if the AlertDialog is already present on top of the screen. Does
anybody has any idea what's wrong here?
public class SMSReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
... //Get the sender address
Intent sendSMSAlert = new Intent();
sendSMSAlert.putExtra(FROM_ADDRESS, fromAdress
sendSMSAlert.setClass(context,
SMSNotificationActivity.class);
sendSMSAlert.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP );
context.startActivity(sendSMSAlert);
}
}
public class SMSNotificationActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
removeDialog(DIALOG_SHOW_MESSAGE);
showDialog(DIALOG_SHOW_MESSAGE);
mFromAddress =
getIntent().getExtras().getString(FROM_ADDRESS);
}
protected Dialog onCreateDialog(int ID)
{
String message = "New Message Received from ";
switch(ID)
{
case DIALOG_SHOW_MESSAGE:
AlertDialog.Builder smsAlertDlgBuilder = new
AlertDialog.Builder(this);
smsAlertDlgBuilder.setTitle("Message Received");
smsAlertDlgBuilder.setMessage(message);
smsAlertDlgBuilder.setPositiveButton(R.string.sms_notification_open,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
// Begin creating the reply with the
SmsMessagingDemo activity
Intent i = new Intent();
i.setClass(SMSNotificationActivity.this,
ViewMessageActivity.class);
startActivity(i);
dialog.dismiss();
finish();
}
});
smsAlertDlgBuilder.setNegativeButton(R.string.sms_notification_dismiss,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
whichButton) {
dialog.dismiss();
finish();
}
});
smsAlertDlgBuilder.setOnCancelListener(new
DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
finish();
}
});
return smsAlertDlgBuilder.create();
}
Android.manifest file:
<activity
android:name=".sms.notification.SMSNotificationActivity"
android:theme="@android:style/
Theme.Translucent.NoTitleBar"
android:launchMode="singleInstance" >
</activity>
// I have tried other values for launch mode as well but nothing
worked.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en