Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App design question: Reconnectable dialogs? #9

Closed
odysseus654 opened this issue Feb 20, 2012 · 5 comments
Closed

App design question: Reconnectable dialogs? #9

odysseus654 opened this issue Feb 20, 2012 · 5 comments

Comments

@odysseus654
Copy link

I'm in the process of adapting my existing code to work with IgnitedAsyncTask (you deprecated android-fu already?) and I'm running into a potential design issue in that most of my asyncTasks are involved in some form of ProgressDialog or AlertDialog, which is tied to the Context object and likely should not survive a reconfiguration.

Is there value in developing a ProgressDialog-like and/or AlertDialog-like object "in the style" of IgnitedAsyncTask that supports .connect() and .disconnect(), recreating the "real" dialog object as-needed (and hooking all the events into itself) ? Or is there a better way to look at this issue that I'm not seeing?

This is not a request for development or a pull request (yet), just a query as to whether this is a good direction to go in, as an issue on a project that seems to deal with these issues as one of its central purposes.

@mttkay
Copy link
Owner

mttkay commented Feb 20, 2012

Hi,

Android has the concept of managed dialogs. You create a managed dialog in Activity.onCreateDialog, and Android will make sure that the dialog will survive configuration changes (i.e. if it was showing during a configuration change, Android will take care of recreating it upon Activity restart). I was actually about to extend IgnitedAsyncTask and ignited-async-task-sample to show how one can leverage IgnitedAsyncTask+IgnitedDialogs+onCreateDialog to have a managed progress dialog show up while a task is running.

@odysseus654
Copy link
Author

I absolutely love the quality of documentation Android has for this, had to read source to figure out what the heck it's trying to do. It does seem like onCreateDialog is used more for assisting in serialization/deserialization of a dialog than a persistent dialog object (although outside an AsyncTask there may not be that much of a difference)

I'm seeing deprecation warnings on nearly every documentation lookup I'm doing here. I know that IgnitedAsyncTask completely unrelated to a Fragment (so using onRetainNonConfigurationInstance still makes sense) but could DialogFragment be useful here?

@odysseus654
Copy link
Author

I threw this together last night, a class "in the style of" AlertDialog.DialogBuilder, intended to be used inside IgnitedAsyncTask (and chained to its connect/disconnect), I'm hoping I'm not going too far "off the rails" here (not yet tested yet): http://pastebin.com/CSd5r5R4

Is there a reason why IgnitedAsyncTask is not using weak references to further reduce the potential for leaked contexts? I haven't used weak references much in java yet, but I would think that they were usable in here.

Lemmie know if this issue is no longer a question and can simply be closed. You are also free to grab the code if you like it (I have a ProgressAlert subclass written/untested as well)

@mttkay
Copy link
Owner

mttkay commented Mar 2, 2012

sorry was gone for a week. The reason why I didn't use weak or soft references is that the premise of the callbacks should be to always have access to a valid context. Well, whether or not it's actually valid depends on whether one called connect/disconnect in the right way, true. In any case though, the reference should not be null, if that was the case, one could use a classic AsyncTask instead where there is no guarantee to have a context reference in e.g. onPostExecute.

@mttkay
Copy link
Owner

mttkay commented Mar 10, 2012

Closed as not being a bug. Feel free to further discuss this on the mailing list.

@mttkay mttkay closed this as completed Mar 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants