Has MvxCachingFragmentCompatActivity disappeared? - android

I'm trying to upgrade to MvvmCross 5.2 and get a syntax error on the MvxCachingFragmentCompatActivity. Has this class disappeared?

As explained in the blog for 5.2: https://www.mvvmcross.com/mvvmcross-52-release/
We've refactored the Android presenter and there is no need anymore for a special Activity like MvxCachingFragmentCompatActivity. The adviced Activity to use now is the MvxAppCompatActivity.

Related

Android Trucaller SDK needs a argument in getProfile

TruecallerSDK.getInstance().getUserProfile();
The above line is not working in Android Studio. Its the exact line copied from the Truecaller official docs. They that getUserProfile does not take any argument but when i write it like this, it doesn't work.
Please help! It requires a FragmentActivity or a Fragment method.
And i am writing this code in my onCreate in MainActivity

Cannot Initialize ViewModel inside Fragment

Hi im using view model class to pass some data to my fragment, I have done the same using activity without having any issue, but using fragment I'm unable to initialize view model class.
mDriversWallet = new ViewModelProvider(requireActivity()).get(DriversWalletViewModel.class);
And it keeps giving me error,
error: no suitable constructor found for ViewModelProvider(FragmentActivity)mDriversWallet = new ViewModelProvider(requireActivity()).get(DriversWalletViewModel.class);
It would be very helpful if some can correct me,
Hi i just found the solution, just to let know others don't get me as a complete idiot :D.This project i have been worked with android studio 3.2 and compileSDKversion 25.So recently i have updated android studio to 3.6 which is latest and compileSDKversion to 28, this viewModel problem occur besause i forget to migrate my code to androidX .After successfully migrate code to androidX problem solved, Thanks and sorry for such a dump question...This answer will help some other who dump like me :D

ViewModelProviders.of(getActivity()) "Cannot resolve method of(android.app.Activity)"

I'm currently trying to share data between my two fragments with the help of a view model Android ViewModels.
In the this article they use "ViewModelProviders.of(getActivity()).get(SharedViewModel.class);" in the Fragment to get the model.
My Problem is, that when I write the exact same line into my fragment, I get a "Cannot resolve method of(android.app.Activity)" error
model = ViewModelProviders.of(getActivity()).get(UserAccountViewModel.class);
Can some one help me with this ?
ViewModelProviders requires that you use FragmentActivity (or something derived from it), not Activity, as the base class of your activities.
You might also get a similiar error like Cannot resolve method 'of(android.support.v4.app.FragmentActivity)' from ViewModelProviders.of(getActivity()) if you were trying to import androidx in your gradle file when your app is still using android.support.v4
This is different to the question being asked but is in the same ballpark and ranks first in Google when I had the problem, so I'm posting it!
Just cast getActivity() to specific activity. It works for me. For example:
model = ViewModelProviders.of((MainActivity)getActivity()).get(UserAccountViewModel.class);

Shortcut for Overriding methods in Android Studio

I have recently migrated to Android Studio and I am pretty used to the Source -> Override/Implement feature in Eclipse.
I was wondering where I could find the same feature on Android Studio. I've tried "Alt-Insert"/Generate-Override methods but I don't find the OnPause() method to override in the list. How do I get the methods that I want to override in the list?
These are the only methods that are available to me on my IDE.
Ctrl + O
should work well in Android Studio.
Press Alt(Left one)+insert.
It shows all the dialog with heading "Generate"
Choose override methods.
Shortcut- Ctrl+O
The method you want to override has to be declared in a class you implement or extend. It might be that your class does not extend Activity (for example). And your project might have to be an android project and not a plain java project.
My understanding is that you need to have the class in your code for Android Studio to offer you the override options pertaining to that class. The image you've posted seems to have only one class.
See how many I got:

Native ActionBar-based tabs with native fragments (with MvvmCross)

I am porting an Xamarin-based Android app to be PCL'ified and MvvmCross'ified so we can target multiple mobile device platforms.
Since this is a line-of-business app where we can dictate the minimum Android OS version, we wish to avoid using the various v4 / v7 etc "Support libraries". We prefer to use all native components that are already part of the OS. So this basically means we only wish to target Jellybean and probably Android v4.2 upwards.
Unfortunately whilst there are lots of examples out there of using MvvmCross with ActionBarSherlock and the SupportActionBar (in a support library), there appears to be no examples of how to wire up MvvmCross with the native ActionBar using native Fragments as tabs.
I'm not expecting someone to post up swathes of code but would really appreciate if someone could give me a few pointers on the best approach to take to achieve this.
I will certainly blog about it once I have a working solution to benefit the whole MvvmCross/Xamarin community.
Thanks.
Probably the most important thing is to use MvvmCross - Hot Tuna Droid Full Fragment Support NUGet library. Then create activity that inherits from MvxActivity and fragment from MvxFragment.
ViewModel for tab fragment set in activity when create this class for TabEventArgs.FragmentTransaction.Add method used in ActionBar.Tab.TabSelected event handler like this:
var tab1 = new TabFragment1 {DataContext = ViewModel};
In TabFragment1 class you can use standard fluent binding method on bindingSet creted by
var bindingSet = this.CreateBindingSet<TabFragment1, MyViewModel>();
I don't know if it is a right way, but work.

Categories

Resources