android-jetpack

Android Navigation Architecture Component - Get current visible fragment

[亡魂溺海] 提交于 2019-12-02 21:39:47
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:defaultNavHost= "true" /> How can I retrieve the current displayed fragment by the Navigation component

BoundService + LiveData + ViewModel best practice in new Android recommended architecture

本小妞迷上赌 提交于 2019-12-02 19:10:50
I been struggling a lot thinking about where to place Android Services in the new Android recommended Architecture . I came up with many possible solutions, but I cannot make up my mind about which one is the best approach. I did a lot of research, and I couldn't find any useful guideline nor tutorial. The only hint I found about where to place the Service in my app architecture is this one, from @JoseAlcerreca Medium post Ideally, ViewModels shouldn’t know anything about Android. This improves testability, leak safety and modularity. A general rule of thumb is to make sure there are no

Navigation View Global Action Back State

六眼飞鱼酱① 提交于 2019-12-02 09:04:30
问题 I have been messing with the Jetpack Navigation component, and I created an activity that uses a navigation drawer. class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val navigationController = findNavController(R.id.navigationHostFragment) navigationView.setupWithNavController(navigationController) val appBarConfiguration = AppBarConfiguration(TOP_LEVEL_DESTINATIONS,

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

北战南征 提交于 2019-12-02 07:54:26
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? ?: return // Set up Navigation val navController = host.navController setupActionBarWithNavController

Setting target resolution for CameraX not working as in documentation

左心房为你撑大大i 提交于 2019-12-02 07:04:28
I want to capture photos with fixed resolution (i.e. 1200x1600 ) using CameraX library. So according to documentation I can set target resolution for ImageCaptureConfig : val imageCaptureConfig = ImageCaptureConfig.Builder() .setLensFacing(CameraX.LensFacing.BACK) .setCaptureMode(ImageCapture.CaptureMode.MAX_QUALITY) .setTargetResolution(Size(1200, 1600)) .setTargetAspectRatio(Rational(3,4)) .build() Documentation describes setTargetResolution method as follows: Sets the intended output target resolution. The target resolution attempts to establish a minimum bound for the image resolution. The

Navigation View Global Action Back State

久未见 提交于 2019-12-02 06:53:51
I have been messing with the Jetpack Navigation component, and I created an activity that uses a navigation drawer. class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val navigationController = findNavController(R.id.navigationHostFragment) navigationView.setupWithNavController(navigationController) val appBarConfiguration = AppBarConfiguration(TOP_LEVEL_DESTINATIONS, drawerLayout) toolbar.setupWithNavController(navigationController, appBarConfiguration) } override fun

Android Navigation Component Not Displaying Fragment

不想你离开。 提交于 2019-12-02 02:12:09
I'm trying to implement the new Android Navigation Component in an existing app. I have 2 fragments that are identical except for their name. When I set the startDestination to fragment2, the fragment seems to be shown correctly. When the startDestination is set to fragment1, I don't see the inflated view but I do see the "Fragment 1 created" toast. What am I doing incorrectly? class Fragment1 : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { Toast.makeText(context, "Fragment 1 created", Toast.LENGTH_LONG).show()

PageKeyedDataSource loadAfter doesnt get fire

血红的双手。 提交于 2019-12-02 01:30:46
In my fragment, I integrated android jetpack paging library and the data source I using PageKeyedDataSource with retrofit API callback. the code runs as excepted and loads the data to recyclerview but after I scroll to the bottom, it supposed to load more data by firing loadAfter function in data source class but it didn't I also switched to ItemKeyedDataSource still it fails to execute is my code wrong or the plugin have an issue! but in some demo apps which I found in GitHub works perfectly I followed there code. please if anyone had this problem and fixed let me know Edit: Using AndroidX

android jetpack project gives archlifecycleversion build error

前提是你 提交于 2019-12-02 01:11:52
问题 I am new to android development and just created my first "hello world" project in android studio 3.2 ( canary ) following this tutorial. https://developer.android.com/jetpack/docs/getting-started and then I just did Build- > make project project tried to build and gave me following error. Could not get unknown property 'archLifecycleVersion' for root project 'JetpackHelloWorld' of type org.gradle.api.Project. UPDATE Dependencies following is the dependencies tag in my app folder build.gradle

How to prevent previous fragment to show up after pressing back button using navigation controller?

我的梦境 提交于 2019-12-01 22:33:23
I am trying to use the navigation controller right now. I want to move from LoginFragment to HomeFragment . In LoginFragment I use this code below to move to HomeFragment . Navigation.findNavController(view).navigate(homeDestination) However, when I tap the back button in the HomeFragment , it will go back to LoginFragment , I expect that when I tap the button it will close the app. In old way, if I use activity instead of using Fragment , I usually do something like this to get that expected behaviour: val intent = Intent(this,HomeActivity::class.java) intent.flags = Intent.FLAG_ACTIVITY