android-jetpack

Unable to clear the back stack of all fragments with Navigation Components

倖福魔咒の 提交于 2019-12-06 03:55:24
I am using the Android Navigation Components and am facing one weird issue. I am not able to clear the back stack for the up button, no matter what I tried. My Navigation graph looks like this: Let's take the LoginFragment for example, <fragment android:id="@+id/loginFragment" android:name="com.yashovardhan99.firebaselogin.LoginFragment" android:label="Login" tools:layout="@layout/fragment_login" > <action android:id="@+id/action_loginFragment_to_welcomeFragment" app:destination="@id/welcomeFragment" app:popUpTo="@+id/nav_graph" app:popUpToInclusive="true" /> </fragment> The Java code to

Android navigation component with shared view models

别说谁变了你拦得住时间么 提交于 2019-12-06 03:21:02
问题 A viewmodel lives and dies with an activity or the fragment it is attached to. This has certain ramifications that it is beyond me why isn't anyone asking about (if we get the Navigation architecture into the picture). According to the latest android blogs and the way navigation framework works , we are recommended to go in the Single Activity Multiple Fragments verse. Supposedly I have the following app design . Activity A (Application Entry Point) ---------- Fragment (A) (Uses ViewModel AB)

Proguard causing runtime exception with Android Navigation Component

荒凉一梦 提交于 2019-12-05 21:48:20
问题 I'm experiencing this crash when using proguard after integrating the NavigationComponent ( android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01 ) into my project with target and compile sdk of 27 2018-05-16 12:13:14.044 24573-24573/com.mypackage.myapp.x E/AndroidRuntime: FATAL EXCEPTION: main Process: com.mypackage.myapp.x, PID: 24573 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myapp.x/com.mypackage.myapp.MainActivity}: android.view

How do I link multiple activities in android navigation editor?

自古美人都是妖i 提交于 2019-12-05 14:51:19
问题 I'm learning android development and the navigation component, trying to link multiple activities as the document had written. But it seems like it's impossible to create action between two activities to a single navigation graph which was reasonable to me as the document had written. The NavController and its navigation graph is contained within a single activity. Therefore, when migrating an existing project to use the Navigation Architecture Component, focus on migrating one Activity at a

How to get lifecycle.coroutineScope with new androidx.lifecycle:*:2.2.0-alpha01

依然范特西╮ 提交于 2019-12-05 01:06:49
On 7th May, 2019 androidx.lifecycle:*:2.2.0-alpha01 was released announcing: This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here. On documentation it's mentioned that I can get the LifecycleScope : either via lifecycle.coroutineScope or lifecycleOwner.lifecycleScope properties But it seems that I'm not able to find none of them. My current dependencises are: def lifecycle_ver = "2.2.0-alpha01" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_ver" implementation "androidx.lifecycle

Update list items in PagingLibrary w/o using Room (Network only)

妖精的绣舞 提交于 2019-12-05 00:09:50
问题 I'm using Paging Library to load data from network using ItemKeyedDataSource . After fetching items user can edit them, this updates are done inside in Memory cache (no database like Room is used). Now since the PagedList itself cannot be updated (discussed here) I have to recreate PagedList and pass it to the PagedListAdapter . The update itself is no problem but after updating the recyclerView with the new PagedList , the list jumps to the beginning of the list destroying previous scroll

How to convert a List<Object> to PagedList<Object> and vice-versa?

ぐ巨炮叔叔 提交于 2019-12-04 23:06:48
PagedList<Object> is used for Android's cool paging library. To make the question as minimal as possible : If i have a list of strings like List<String> stringList; // it consists of 200 strings I want to convert stringList to type PagedList<String> like PagedList<String> pagedStringList; And also if i have a PagedList<Object> how can convert it to a List<Object> ? I went through this for reference If i try the other way round .... How can I convert List<Object> into DataSource.Factory<Integer, Object> ..so that indirectly i can convert it into PagedList<> ? From DataSource.Factory<Integer,

Unique OneTimeWorkRequest in Workmanager

对着背影说爱祢 提交于 2019-12-04 19:13:27
问题 We are using OneTimeWorkRequest to start background task in our project. At application start, we are starting the OneTimeWorkRequest (say req A) Depends on user's action we start the same work request A. At some cases, if the app gets killed when the work request A is in progress, Android automatically restarts the request A when the app restarts. Once again we are also starting the request A again. So two instances of the request A runs in parallel and leads to a deadlock. To avoid this, I

Shared ViewModel lifecycle for Android JetPack

淺唱寂寞╮ 提交于 2019-12-04 11:52:13
问题 The documentation https://developer.android.com/topic/libraries/architecture/viewmodel#sharing describes how we can share the same ViewModel across the different Fragments. I have some complicated pages in my single Activity app with a container and tabs fragments. Each such page has own ViewModel which should be shared with all contained fragments. The key trick here is to use Activity instead of Fragment to hold my ViewModel. The problem is that my Activity can have multiple pages with own

Android architecture component navigation: toolbar back button missing, back not working

删除回忆录丶 提交于 2019-12-04 06:18:22
问题 I'm trying the jetpack navigation and can't show the navigation back button when I move to a new fragment. NavigationActivity.kt class NavActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_navigation) val toolbar = findViewById<Toolbar>(R.id.toolbar) setSupportActionBar(toolbar) val host: NavHostFragment = supportFragmentManager .findFragmentById(R.id.navigation_graph) as NavHostFragment? ?: