how to create alertdialog outside of an application?

狂风中的少年 提交于 2019-12-02 09:52:28

I am using the same functionality in my app where i used one activity as a pop up message like below

 @Override
public void onReceive(Context context, Intent intent) {


    try {
         Bundle bundle = intent.getExtras();
         String message = bundle.getString("alarm_message");

         Intent newIntent = new Intent(context, PopupActivity.class);
         newIntent.putExtra("alarm_message", message);
         newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
         context.startActivity(newIntent);
        } catch (Exception e) { 
         e.printStackTrace();

        }
}

In the Popup Activity design the UI like the dialog box and add this in Android Manifest.xml

 <activity android:name=".PopupActivity"
             android:theme="@android:style/Theme.Dialog"
             android:label="@string/label"
             ></activity>

You can customise the UI based on your specification.Its working perfectly for me. I hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!