Android: Dialog triggered onResume - java

I am experiencing a weird behavior in my app.
I have an Activity with a ListView. When you click on an item in the ListView, a TimePickerDialog is shown.
If I hit the home button after closing the dialog, and then reload the app, the TimePickerDialog is shown automatically again.
Now, I don't know why this behavior happens. I have logged messages at different points in the app to try to determine how it is triggered but to no avail.
I even added this line:
Log.d("TEST", "TEST");
inside the constructor of the TimePickerFragment and it is not getting fired! Yet the dialog is showing up!
What is going on here?

The activity will save the state. So it will also save state for managed dialogs. When you come back, it will restore. Since it is already created, constructor wont be called. As far as i know if you do not let the activity manage the dialogs, this behavior will not occur

Thanks to nandeesh's answer, I was able to figure out how to fix that behavior.
Since my dialog was managed, I had to call the dismissAllowingStateLoss() method on my dialog instance.
Works like a charm now.

Related

onCreate called again when resize in multiview/split screen

When I change the screen size in the multiview / split screen mode, the onCreate function in MainActivity is called again.
Because in onCreate I have a ProcessLifecycleOwner observer:
ProcessLifecycleOwner.get().GetLifecycle().AddObserver(this);
I don't want it to be restarted ... How do I know that onCreate has been called before?
I know you can add:
android:configChanges="screenSize"
in the manifest, but unfortunately needs to "refresh the layout" when resizing.
Android is going to manage the life cycle, and the programmer needs to deal with all eventualities. On this page, there's an abbreviated diagram:
That would indicate that you would need to manage the observer in the onStop().

How to create a fully unclosable ProgressDialog?

How to show a ProgressDialog from a background service that is unclosable in any way, displayed above whole screen, above any app, including keys? I mean a dialog exactly like the "Power off.. shutting down" one that is displayed when phone is shutting down, when you can neither do anything to make it disappear nor click anything below it.
PS. If the app needs to be a system app to create such dialog, that's not a problem for me.
Use this
ProgressDialog.setCancelable(false);
Create a full screen activity Using full screen Activity prevent back navigation by overriding onBackPressed()
Disable back button in android

Way to successfully change Content View?

I have an app that uses this RibbonMenu and I wanted to know if it was possible to use the menu items to change the ContentView of the Activity instead of another activity to reduce the size of my app. I've tried doing this already,and it changed the content view perfectly, but i was not able to press the home button. I'm in a bit of a rush here, but i'll try to post code if anyone asks for it. thank you!
Menu items is UI element. It does nothing by itself. It however can trigger some more actions in your code. As for changing activity layout, yes, you can call setContentView() at any time you want.
to reduce the size of my app
this is not the way optimalizations should be done

Is Dialog.show() a non-blocking method?

I've got a button that kicks off a background thread to do some work and I am trying to use a ProgressDialog to prevent the user from double clicking that button (or any other ui elements) while that work is being done. The first thing I do in my buttons onClick code is to display the progress dialog, which takes over the screen. The problem I am seeing is that if I rapidly tap this button, sometimes two or more presses will register before the ProgressDialog is shown. This leads me to assume that ProgressDialog.show() is returning before the ProgressDialog is actually visible.
Can anybody confirm this? Also, is there a way to change this behavior, or at least get a notification of when the dialog is actually visible? I saw Dialog.onStart() but given the javadoc, this appears to be called before the Dialog is actually visible...
UPDATE:
While it appears that there is no good way of solving this problem in general, the following works for my situation where my work is done by an external thread and the amount of work to do takes longer than the time it takes for all the button clicks to be processed:
void myOnClickHandler() {
if(myButton.isEnabled()) {
myButton.setEnabled(False);
// do work here
// setEnabled(true) is invoked at the end of my spawned thread's run().
}
}
No.
The problem is you clicked many times before the click event is delivered. (i.e. it is queued before you run ProgressDialog.show().)
From what I've noticed in Android you can double click on a button rapidly and have the onClick listener fire twice (or even more) regardless of the code in the listener (even if you disable the button immediately).
I reported a bug a while ago here: http://code.google.com/p/android/issues/detail?id=20073 but of course these things tend to go "unnoticed" by Google. Feel free to star it in hopes of getting Google's attention

Why doesn't my Android activity refresh/redraw?

RoomInfoActivity.java: http://pastebin.com/L9fFsFeH
(note: this is the 3rd activity launched by the same application, not that it should matter..)
AndroidManifest.xml: http://pastebin.com/QbvQaTf3
room_info.xml: http://pastebin.com/DFNABSNF
Image: http://dl.dropbox.com/u/16952797/temp_stuff/elfapp_ss04.PNG
(note: when I click on the button, "nothing" happens.)
Description: So what happens is the code compiles just fine, and the .apk is launched and run without any issues, but the RoomInfoActivity doesn't reflect the changes that are supposed to be made (such as changing the text of the TextViews and Button) when I click on the button. I'm looking for the least complicated way to do these.
EDIT: I have now made a change, I added this line buttonCleaned.setClickable(true);
under this:
rumInfo.setText(getIntent().getExtras().getString("entry"));
buttonCleaned.setText("Färdig med städningen");
rumStatus.setText("Status: "+checkStatus());
Is your onClick() method ever called? I think you need to set the Activity as a click listener on the button, using the setOnClickListener method.

Categories

Resources