0

When an android device is rotated, activity is normally recreated.

If I would like to display an alert/progress bar from my MvvmCross view model (or do something else requiring a living activity instance), what is the recommended way of handling rotation?

-----Added example-----

Currently we are working using MVP style.

Presenter has a reference to the view interface, and it can call methods like view.DisplayDialog, view.DisplayError or view.DisplayProgress.

Android implementation does something like this:

var dialog = AlertDialog.Builder(this)

or

Toast.MakeText(BaseContext, message, ToastLength.Long);

or

_progressDialog = new ProgressDialog(this);
_progressDialog.SetTitle(title);
_progressDialog.SetMessage(message);
_progressDialog.SetCancelable(false);
_progressDialog.Show();

In all these cases a reference to the Context (i.e. activity) is necessary.

Now, moving to MVVM style and MvvmCross, how would you change this kind of code?

Paul Kapustin
  • 3,265
  • 5
  • 34
  • 45
  • Is there any more info you can provide on this? Perhaps some sample code that illustrates the problem? I'm confused because (to me) displaying a ProgressBar is just like displaying any other View - http://developer.android.com/reference/android/widget/ProgressBar.html - an example of it bound is in https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20TwitterSearch/TwitterSearch.UI.Droid/Resources/Layout/Page_Twitter.axml (the RSS feed in that app sadly now broken by Twitter) – Stuart Sep 01 '13 at 20:50
  • I have added an example/a little bit of code to illustrate what I was thinking. – Paul Kapustin Sep 04 '13 at 14:37
  • If this is mainly about Android Dialog lifecycle, I think this is covered in questions like http://stackoverflow.com/questions/7557265/prevent-dialog-dismissal-on-screen-rotation-in-android - there's lots of info on the old `showDialog` api and the newer `Fragment` approach (confusingly, fragment lifecycles are independent of their activities). – Stuart Sep 04 '13 at 20:25
  • This is only partially on the lifecycle, but mainly I am trying to understand what would be a good way of doing these kind of things in MvvmCross, from ViewModels, where you do not have a direct reference to the view (what makes it somewhat complex to perform context-dependent operations, but what is also good, because then you don't have to fear NullReferenceException when the view gets recreated) – Paul Kapustin Sep 05 '13 at 09:30

0 Answers0