How to check if activity is in foreground or in visible background?

This is what is recommended as the right solution: The right solution (credits go to Dan, CommonsWare and NeTeInStEiN) Track visibility of your application by yourself using Activity.onPause, Activity.onResume methods. Store “visibility” status in some other class. Good choices are your own implementation of the Application or a Service (there are also a few variations … Read more

Receive result from DialogFragment

Use myDialogFragment.setTargetFragment(this, MY_REQUEST_CODE) from the place where you show the dialog, and then when your dialog is finished, from it you can call getTargetFragment().onActivityResult(getTargetRequestCode(), …), and implement onActivityResult() in the containing fragment. It seems like an abuse of onActivityResult(), especially as it doesn’t involve activities at all. But I’ve seen it recommended by official google … Read more

Choose File Dialog [closed]

You just need to override onCreateDialog in an Activity. //In an Activity private String[] mFileList; private File mPath = new File(Environment.getExternalStorageDirectory() + “//yourdir//”); private String mChosenFile; private static final String FTYPE = “.txt”; private static final int DIALOG_LOAD_FILE = 1000; private void loadFileList() { try { mPath.mkdirs(); } catch(SecurityException e) { Log.e(TAG, “unable to write … Read more

How to dismiss the dialog with click on outside of the dialog?

You can use dialog.setCanceledOnTouchOutside(true); which will close the dialog if you touch outside of the dialog. Something like, Dialog dialog = new Dialog(context) dialog.setCanceledOnTouchOutside(true); Or if your Dialog in non-model then, 1 – Set the flag-FLAG_NOT_TOUCH_MODAL for your dialog’s window attribute Window window = this.getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); 2 – Add another flag to windows properties,, … Read more

How to change DatePicker dialog color for Android 5.0

The reason why Neil’s suggestion results in a fullscreen DatePicker is the choice of parent theme: <!– Theme.AppCompat.Light is not a dialog theme –> <style name=”DialogTheme” parent=”**Theme.AppCompat.Light**”> <item name=”colorAccent”>@color/blue_500</item> </style> Moreover, if you go this route, you have to specify the theme while creating the DatePickerDialog: // R.style.DialogTheme new DatePickerDialog(MainActivity.this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() { @Override … Read more

How to make an alert dialog fill 90% of screen size?

According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window’s top level layout width and height to WRAP_CONTENT. To make the Dialog bigger, you can set those parameters to MATCH_PARENT. Demo code: AlertDialog.Builder adb = new AlertDialog.Builder(this); Dialog d = adb.setView(new View(this)).create(); // (That new View is just there … Read more

How to show details of current row from p:dataTable in a p:dialog and update after save

The button should be an ajax button which sets the currently iterated entity in the bean, and then updates the dialog’s content, and finally shows it. The dialog should just reference that entity in the bean and update the list and table on save. It’s very important that dialog is placed outside the main form … Read more

How to display a Dialog from a Service?

We can show dialog from service only if it is a system alert dialog. So, set TYPE_SYSTEM_ALERT window layout parameter to Dialog as follows: dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); But, it needs SYSTEM_ALERT_WINDOW permission. So, don’t forget to add this permissin in Manifest file. <uses-permission android:name=”android.permission.SYSTEM_ALERT_WINDOW”/> Edit: Better option to show dialog is to start activity as one of … Read more