android-architecture-components

How to Have Navigation Drawer setup with Navigation Controller and handle individual Menu Items

余生颓废 提交于 2019-12-19 10:19:12
问题 I would like to have most of menu item handled by Navigation Component's controller, but I also want to handle one "Log out" menu item individually like this: val navController = findNavController(R.id.nav_host_fragment) nav_view.setNavigationItemSelectedListener { item -> when(item.itemId) { R.id.logout_menu_item -> { Toast.makeText(context, "Logut Menu Item Touched", Toast.LENGTH_LONG).show() true } else -> false } } nav_view.setupWithNavController(navController) bottom_navigation

Periodic daily work requests using WorkManager

我是研究僧i 提交于 2019-12-18 20:47:15
问题 How to properly use the new WorkManager from Android Jetpack to schedule a one per day periodic work that should do some action on a daily basis and exactly one time? The idea was to check if the work with a given tag already exists using WorkManager and to start a new periodic work otherwise. I've tried to do it using next approach: public static final String CALL_INFO_WORKER = "Call worker"; ... WorkManager workManager = WorkManager.getInstance(); List<WorkStatus> value = workManager

Navigation Component set transition animation programmatically

北城余情 提交于 2019-12-18 13:41:53
问题 yesterday i come across with a problem that i needed to set animation from nav_graph.xml in my baseFragment and programatically get action object from current node which includes enterAnim and exitAnim resource. Could not find solution here so here we go. First we need to feed anim folder with our animations in res folder because its hungry. slide_in_left.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration=

How to select from multiple databases in Android Room(How to attach databases)

拈花ヽ惹草 提交于 2019-12-18 13:09:41
问题 As you know we can select from multiple databases using attach command like this: String path = DBHelper.getDatabasePath(context); String sql = "ATTACH DATABASE '" + path + "/" + dbname.toString() + ".db' AS \"" + dbname.toString() + "\";"; db.execSQL(sql); Then by using Cursor, we can do select from them. By using Android Room, How can I do this? Is there any attachment or similar command to do this? 回答1: Can use this code for attach another database @Database(entities = {Book.class, User

Cannot create an instance of class ViewModel

蓝咒 提交于 2019-12-18 12:44:48
问题 I am trying to write a sample app using Android architecture components and but even after trying for days I could not get it to work. It gives me the above exception. Lifecycle owner:- public class MainActivity extends LifecycleActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = findViewById(R.id.tv_user); PostViewModel viewModel = ViewModelProviders.of(this).get(PostViewModel.class);

Navigation Architecture Component - Dialog Fragments

孤街浪徒 提交于 2019-12-18 12:07:33
问题 Is it possible to use the new Navigation Architecture Component with DialogFragment? Do I have to create a custom Navigator? I would love to use them with the new features in my navigation graph. 回答1: No, as of the 1.0.0-alpha01 build, there is no support for dialogs as part of your Navigation Graph. You should just continue to use show() to show a DialogFragment . 回答2: May 2019 Update : DialogFragment are now fully supported starting from Navigation 2.1.0-alpha03 , you can read more here and

Android Navigation Component pop to transition issue

懵懂的女人 提交于 2019-12-18 11:53:26
问题 I have 2 actions Action1 <action android:id="@+id/actionBaseFragmentToAskForLocation" app:destination="@+id/introAskForLocationFragment" app:enterAnim="@anim/slide_in_right" app:exitAnim="@anim/slide_out_left" app:popEnterAnim="@anim/slide_in_left" app:popExitAnim="@anim/slide_out_right" /> Action2 <action android:id="@+id/actionIntroAskLocationToLogin" app:destination="@id/loginFragment" app:enterAnim="@anim/slide_in_right" app:exitAnim="@anim/slide_out_left" app:popEnterAnim="@anim/slide_in

Android JetPack navigation with multiple stack

隐身守侯 提交于 2019-12-18 11:19:09
问题 I'm using Jetpack Navigation version 1.0.0-alpha04 with bottom navigation. It works but the navigation doesn't happen correctly. For example, if I have tab A and tab B and from tab A I go to Page C and from there I go to tab B and come back to tab A again, I will see root fragment in the tab A and not page C which does not what I expect. I'm looking for a solution to have a different stack for each tab, so the state of each tab is reserved when I come back to it, Also I don't like to keep all

Android Jetpack Navigation with ViewPager and TabLayout

对着背影说爱祢 提交于 2019-12-18 10:42:54
问题 For a new app i use Jetpack Navigation Library to implement proper back navigation. The first level of navigation is a navigation drawer which works fine with jetpack navigation as described in the documentation. But there is another level of navigation implemented with ViewPager and TabLayout. The fragments switched by the TabLayout contain additional linear navigation hierarchy. However, there seems to be no support for ViewPager/TabLayout in Jetpack Navigation. A FragmentPagerAdapter has

Cannot create an instance of custom ViewModel

孤人 提交于 2019-12-18 05:42:17
问题 I am using dagger2 library. whenever I am trying to run my project is says not able to create instance of view model class. main activity where I am trying to create an instance ((MovieApplication) getApplication()).getAppComponent().inject(this); mViewModel = ViewModelProviders.of(this).get(MoviesDataViewModel.class); My factory class public class ViewModelFactory implements ViewModelProvider.Factory { private MoviesDataViewModel mViewModel; @Inject public ViewModelFactory