When my app gets started it executes an AsyncTask, which checks a page, for a never version of this app. If so, it displays an AlertDialog. But right after the UpdateCheck gets executed, the MainActivity starts a new Intent and a new Activity and so the Alertdialog of the AsyncTask won't get displayed until I return to the MainActivity. Is there a way around to show it independend of the Activity or something like a global Dialog? Thanks in advance.
Related
In my activity needs to download an image from a webservice, therefore I wrote an updateUi method which get called in onCreate() to hide the ui elements (because of missing data at this time) and to show a simple TextView with a message like "data loading...".
Then I use the onWindowFocusChanged with a loaded boolean to call it only one time. In the onWindowFocusChanged I download all data I need from the webservice and call updateUi again to show the original ui and hide the "data loading" TextView.
The goal is to immediately open the new activity after the user pressed a button instead of hidden processing while the user don't know what's happening.
I have like 10 other activities where this method works very well without any trouble, but in this particular activity it seems like onWindowFocusChanged get called before the new activity shows up. If I click on the button to open the activity nothing happens on the display for some secs and then the activity starts with the original ui with all data filled in.
I don't understand why the activity doesn't show up with the "data loading.." TextView instead of doing the tasks in onWindowFocusChanged while the activity didn't show up already?
The code is the same like in my other activities, does someone have any experience with this issue?
I have noticed, that the problem doesnt exists in the first creation of the activity. if i click on a button which start the activity the first time the textview with the loading message is showing and the other ui elements are hidden.
if i leave the activity an start it again the problem occurs...
I have an quiz app. and i want the user to choose the type of questions from alert dialog . so the alert dialog has a check boxes buttons so if the user can select more then on type. when the user click the positive button in alert dialog it will send info to if condition then the condition will filter the questions and then will pass it to an array. the problem is the array its inside oncreate and i want the alert dialog to be in same class so when i run the class oncreate will start and i get null exception because i didn't pass any info to the array.
How can i delay oncreate() and make it load only after the user click on positive button of alert dialog.
The alert dialog will be in same class .
So how can i do it ? is it possible?
and thanks.
onCreate() is the first called when the activity is created per the android activity lifecycle so, no. I'm not sure why you would want it in the same activity if you don't want it to start unless they click 'OK'. Put it in it's own class or the previous activity.
No you cannot, if you attempt to delay something within the OnCreate() method within an activity it will throw an exception as you don't have a context to place the alert dialog in at that time. As codeMagic previously stated, if you have a prior activity before this one, your best bet would be to create the alert prior to calling startActivity on that intent.
I would suggest to use Fragments in this case. Load Activty, show dialog and based on the answer you will display "correct answer fragment" or "invalid answer fragment".
With this solution activity is loaded (no need to delay) and you just dynamically change the content of the activity.
Try using the AsyncTask class. The onPostExecute method may do the job you're looking for ..
I'm trying to build a notepad application in android. I'm in this situation, when the user chooses to create a new file while still working on a file, the application should first ask for a save and then restart the MainActivity to create the new file.
So, basically, the sequence is as follows:
->Working on current file
->Clicks on New File
->Save dialog
->Restart MainActivity.
For this, I've been using a method called new file as below:
public void new_file()
{
save_file();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
The problem here is that, everytime I run the application and text this part of the code, the dialog pops up and immediately a new file.
I would like to know how I can first let the Activity finish the save_file() method call and then the Activity Restarts.
Thanks in Advance
It looks like it works fine, but not seeing safe_file() code (BTW: consider switching to more standard function naming convention) it's hard to be sure , but note dialogs are asynchronous, so you cannot start dialog and expect all further code to wait for dialog dismiss. I assume you popup dialog in safe_file() method, so you should either call back to start new activity from there when done saving or you should do that in your dialog click listener.
Use the Negative, Positive and Neutral buttons of the AlertDialog mechanism to detect when a user has exited the dialog. Then, use an OnClickListener to decide which button was clicked, and only restart the Activity then. Something like:
Show dialog
Wait for one of the buttons to be clicked
Restart activity when a button is clicked, as that means the user is exiting the dialog.
Is it possible to show an alertDialog that is still showing when starting a child activity?
I am asynchronously fetching results from a server. The request is sent from activtiy A which then shows a progressDialog. When the first result is received, activity A starts activity B, which will receive the following results. But the progressDialog shown from A should still be shown when B starts.
How can I do this?
thanks
I'm not sure if it will work but you could try changing the owner activity from Activity A to Activity B with: Dialog.setOwnerActivity() for more info see the dialog docs
I have the following problem:
I have an Activity where a user can start a web search showing a new activity to show a progress bar until the results are shown. Now the user can either wait for the results or maybe think about the search parameters, hit the back button and triggering a new search. The search is running in an Async Task and therefor still running if the user hits back.
At the moment the thread finishes it calls some methods on the old activity causing the activity to show a dialog.
This causes the system to crash because the dialog tries to show itself with a reference to an activity that is not longer present on the screen.
How can I achieve a dialog that is only shown if the activity is still active?
Call isFinishing() on your activity.