I want to show a dialog (kind of splash screen) when my application is opened. Therefore I put a create and show dialog into onCreate(). The dialog opens indeed but first, the empty activity (white background) is shown.
There must be a possibility to prevent that empty screen to be shown? A lot of apps have a behaviour like that. I would like to have the dialog as the actual first screen to be shown to the user.
it would be better if we have code to see tasks taking time as per general solution
Android SplashScreen
Show spinning wheel dialog while loading data on Android
http://blog.iangclifton.com/2011/01/01/android-splash-screens-done-right/
Related
I want to show an Alert Dialog such that it stays on screen even if I go back to previous activity just after showing an alert dialog. Is is possible?
I tried using applicationContext but it does not work.
I don't think so, and I believe this would be a bad user experience. Perhaps you should re-think the design.
You cant do that , because a dialog is attached with a single window context , if window changes the dialog memory will be leaked and it will automatically close the dialog .You can make a same effect by showing the same dialog in both screens .However you will definitely see the transition of dialog with activity .
You can create an activity and give it a dialog theme. That way you dont have to worry about the context. It doesnt make a difference to the user also as it looks just like a dialog.
But I agree with AndyRes, It would be a bad user experience.
I have read really a lot of posts about this topic, however nothing works for me (or doesn't have the effect I wish).
I have a an application, that after logging in starts a background Service (implementation of the Service class). This service syncs itself with a Server and if a new order comes, it creates a notification.
So far, everything works great, I have the notification and the Toast message. However, I would like to have a dialog, that notifies the user about the new order.
As I understood, you can start an activity from within the service, which displays the dialog. This works, but the activity starts on top of the current activity stack and displays the dialog. I have an activity with no view attached and it correctly displays the dialog, however, on a black background.
What I want is to display the dialog on the current activity, causing the actual background(the running activity) to fade and display the dialog.
Is this somehow possible?
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 the below ways.
Start Activity with Dialog Theme (android:theme="#android:style/Theme.Dialog") -(or)
Start Translucent Activity and show Dialog in it.
Note: You should add Intent.FLAG_ACTIVITY_NEW_TASK to intent
I highly, highly, HIGHLY recommend that you DON'T do this (it goes against Android design and UI guidelines). Notifications are the preferred way to accomplish what you are doing (which it sounds as if you have already accomplished).
That being said, if you must do it, I would recommend just using a Dialog themed activity. That way you don't have to start up a separate dialog. Please see http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme for how to do this.
you can start by learning on how to create an activity that looks like a dialog (no title bar, transparent background, "floating" effect, etc.)
and no, you can't just start a dialog without an activty
No, you can't hijack activity that is not "yours" and command it to show dialog.
Your approach of starting your own activity is the classic one.
You cannot show a dialog. But you can go the alernative way by inflating your customized view so that you can show a dialog on the screen whenver certain conditions are met.
I am uploading/downloading some data in my application using AsyncTask. What I want is that, when the AsyncTask is running, the whole screen should get dimmed/disabled and a ProgressBar would be shown in the middle of the screen as long as the task is running.
Something like this
Any ideas / suggestions are most welcome.
Really need to implement it in my application!
the default "Dialog" theme does just that. You can do this
launch a new activity with the Dialog theme
the xml of that activity must have no background image/colour
show your dialog in the new activity
finish the activity, when the dialog is dismissed acc to your program logic
in the picture the dialogue is a Dialogue Activity. You can search on Goolge how to implement dialogue Activity :)
I want to show two Dialogs (default) at the same time, no matter if second one is shown then previous lost its focus but should remain on the Screen. I tried by many ways such as:
1) Creating two Alert Dialogs
2) Creating one Alert Dialog and other one Activity as a Dialog
but i never achieved my desired task. Image is shown below that just describes how i want to show such Dialogs (default) and layout would be same as to the Default dialog but here i just describe how should the dialogs be laid out.
It's not possible to show two dialogs at the same time in the same activity.
If you do want something that looks like a second dialog, I suggest you create a layout inside the first dialog that is hidden until you make some selection.
My application displays alert dialogs in some cases. Also, it is possible for a user to launch my application using the VIEW/SEND intent. The scenario I am considering is, the dialog is visible, the user presses 'Home' & selects my application to View/Share a file.
I would want to dismiss the dialog before beginning with the view/share operation. Although I can maintain which dialog is visible and hide it before the operation begins, I was wondering if there is a conventional/recommended way or API, something like activity.dismissAnyVisibleDialog() that can come in handy.
Thanks a lot,
Akshay
I finally myself maintained which dialog is visible & dismissed it before displaying the next one.
-Akshay
Just close the dialog in the onPause() method (override in your activity).
This way it will be dismissed when the activity is no longer visible i.e if you switch to the home screen.