android-jetpack

Proguard causing runtime exception with Android Navigation Component

南笙酒味 提交于 2019-12-04 04:41:32
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.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment at android.app

Android Jetpack Navigation library and onActivityResult

纵然是瞬间 提交于 2019-12-04 02:53:48
I'm trying to migrate an app to the new Navigation Architecture Component that was announced at GoogleIO'18 Suppose I need to use an activity that is normally started with startActivityForResult . This activity comes either from a library or a system activity, so I can't modify it. Is there any way to include this activity as a destination in the navigation graph and get results from it? The only solution I have so far is to wrap that activity behind a fragment that catches the result and then presents it to the navigation graph: class ScannerWrapperFragment : Fragment() { private val

How do I link multiple activities in android navigation editor?

随声附和 提交于 2019-12-04 01:12:32
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 time by creating a navigation graph for the destinations within each Activity. So the question is what

Unique OneTimeWorkRequest in Workmanager

﹥>﹥吖頭↗ 提交于 2019-12-03 12:23:26
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 did below code in app start to check if the worker is running but this always returns false. public

Remove up button from action bar when navigating using BottomNavigationView with Android Navigation UI library

隐身守侯 提交于 2019-12-03 09:14:50
问题 I've created a small app that has three fragments for top-level navigation through a BottomNavigationView. If you launch the app and click on a navigation button on the bottom nav, you are presented with an up button in the action bar. Here is the code for the activity: class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.main_activity) setSupportActionBar(toolbar) val navController =

PagedListAdapter jumps to beginning of the list on receiving new PagedList

[亡魂溺海] 提交于 2019-12-03 08:16:54
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 position. Is there anyway to update PagedList while keeping scroll position (like how it works with Room

Android Navigation Architecture Component - Get current visible fragment

假装没事ソ 提交于 2019-12-03 08:06:10
问题 Before trying the Navigation component I used to manually do fragment transactions and used the fragment tag in order to fetch the current fragment. val fragment:MyFragment = supportFragmentManager.findFragmentByTag(tag):MyFragment Now in my main activity layout I have something like: <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/nav_host" app:navGraph= "@navigation/nav_item" android:name="androidx.navigation.fragment.NavHostFragment" app

Shared ViewModel lifecycle for Android JetPack

﹥>﹥吖頭↗ 提交于 2019-12-03 06:51:36
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 models and holding the view model for particular page all the time is waste of device resources. Is

How to get a result from fragment using Navigation Architecture Component?

只愿长相守 提交于 2019-12-03 06:46:09
问题 Let's say that we have two fragments: MainFragment and SelectionFragment . The second one is build for selecting some object, e.g. an integer. There are different approaches in receiving result from this second fragment like callbacks, buses etc. Now, if we decide to use Navigation Architecture Component in order to navigate to second fragment we can use this code: NavHostFragment.findNavController(this).navigate(R.id.action_selection, bundle) where bundle is an instance of Bundle (of course)

How to make retrofit API call using ViewModel and LiveData

只愿长相守 提交于 2019-12-02 22:47:51
this is the first time I'm trying to implement MVVM architecture, and I'm a bit confused about the correct way to make an API call. Currently, I'm just trying to make a simple query from the IGDB API, and output the name of the first item in a log. My activity is setup as follow: public class PopularGamesActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_popular_games); PopularGamesViewModel popViewModel = ViewModelProviders.of(this).get(PopularGamesViewModel.class);