Pass ReactiveObject ViewModel between Android Activity in Xamarin

I am using ReactiveObject

both ViewModel

in Xamarin.PCL

:

public class PlanViewerViewModel : ReactiveObject

      

There ViewModel

is a lot of logic inside ReactiveUI

, for example:

FilterIssueTypeCommand = ReactiveCommand.Create<string, List<IGrouping<int, StandardIssueTypeTable>>>(
                searchTerm => 
                {
                    Func<StandardIssueTypeTable, bool> filterIssueType = d =>
                        string.IsNullOrEmpty(this.IssueTypeSearchQuery) ? true :
                        Contains(d.Title, this.IssueTypeSearchQuery) ||
                        Contains(d.Category.Title, this.IssueTypeSearchQuery) ||
                        Contains(d.Issues.Count().ToString(), this.IssueTypeSearchQuery);

                    return RealmConnection.All<StandardIssueTypeTable>().Where(filterIssueType)
                                          .GroupBy(g => g.CategoryId)
                                          .ToList();
                }
            );

this.WhenAnyValue(x => x.IssueTypeSearchQuery)
    .Throttle(TimeSpan.FromMilliseconds(500), RxApp.MainThreadScheduler)
    .Select(x => x?.Trim())
    .DistinctUntilChanged()
    .InvokeCommand(FilterIssueTypeCommand);

_groupedStandardIssueType = FilterIssueTypeCommand.ToProperty(this, x => x.GroupedStandardIssueType, new List<IGrouping<int, StandardIssueTypeTable>>());

      

In development, Xamarin.iOS

I could easily pass ViewModel

between each controller with this code:

var finderController = segue.DestinationViewController as PVFinderTabBarController;
finderController.ViewModel = this.ViewModel;

      

I am wondering how could I do this in Xamarin.Android

?

I know there are several ways to transfer data between Activity

:

  • Give it as string

    , int

    , bool

    : This is what I'm using now
  • Serialize object to JSON

    : slow
  • Embed Parcelable

    or Serializable

    : I don't want to use it because that means I need to copy the project ViewModel

    to Xamarin.Android

    .

If I do that, there is no point in using ReactiveUI

.

I am thinking to use the class Application

in Android

and create one instance of mine ViewModel

in it so that everyone Activity

can reference this. Something like that:

[Application]
public class GlobalState: Application
{
    public PlanViewerViewModel viewModel { get; set; }
}

      

Is there any other solution?

+3
android c # xamarin xamarin.android reactiveui


source to share


No one has answered this question yet

Check out similar questions:

6155
What is the difference between string and string in C #?
5641
What is the difference between "px", "dip", "dp" and "sp"?
3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2735
Stop EditText from getting focus when Activity starts
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
1296
Reloading activity on android rotation
1270
How to pass data between activities in an Android app?



All Articles
Loading...
X
Show
Funny
Dev
Pics