android-jetpack

CameraX - crash when unbinding Preview UseCase

て烟熏妆下的殇ゞ 提交于 2020-04-16 05:50:19
问题 I need to freeze (stop) the preview when user initiates taking the photo. I've searched around and I've found this SO post that mentions unbinding Preview UseCase. I've tried that and at first it works correctly on Android 9+, but on lower Android I receive following error in Logcat and picture is not taken. ImageCapture: takePictureInternal onFailure androidx.camera.core.ImageCaptureException: The completer object was garbage collected - this future would otherwise never complete. The tag

How to use Navigation Drawer and Bottom Navigation simultaneously - Navigation Architecture Component

和自甴很熟 提交于 2020-04-10 07:54:32
问题 I have screen like below which contain a navigation drawer and bottom navigation on same screen: I am using Jetpack Navigation Architecture Component. Current issue and What I have tried? Clicking on the 2nd and 3rd bottom nav item shows back arrow on toolbar? Tried: setting fragments associated with 2nd and 3rd bottom nav to top level destinations appBarConfig = AppBarConfiguration(setOf(R.layout.fragment_star, R.layout.fragment_stats, R.layout.fragment_user)) instead of appBarConfig =

How to use Android Navigation Component + BottomNavigationView+ NavigationView (Navigation Drawer)

自闭症网瘾萝莉.ら 提交于 2020-04-10 03:31:31
问题 I would like to know what is the best practice of using Navigation Component + BottomNavigationView + NavigationDrawer. I have tried google's advanced sample for Navigation component. It worked very well for multiple back stack modules. Because it has a workaround extension. When using this approach, each bottom tab has its own graph and the graphs change as you select one of the tabs. But when NavigationView is integrated, it needs to know the navigation graph in advance. But in advanced

How to use Android Navigation Component + BottomNavigationView+ NavigationView (Navigation Drawer)

可紊 提交于 2020-04-10 03:30:27
问题 I would like to know what is the best practice of using Navigation Component + BottomNavigationView + NavigationDrawer. I have tried google's advanced sample for Navigation component. It worked very well for multiple back stack modules. Because it has a workaround extension. When using this approach, each bottom tab has its own graph and the graphs change as you select one of the tabs. But when NavigationView is integrated, it needs to know the navigation graph in advance. But in advanced

How to use a ViewModelProvider.Factory when extends from AndroidViewModel

99封情书 提交于 2020-04-06 02:34:19
问题 I want to send an extra parameter to my ViewModel, but this extends from AndroidViewModel . How can I add this parameter to the ViewModelFactory class ? ViewModel class ProjectViewModel(application: Application) : AndroidViewModel(application) { // need a param for project id... } ViewModelFactory class ProjectViewModelFactory(val projectId: Int): ViewModelProvider.Factory { override fun <T : ViewModel?> create(modelClass: Class<T>): T { // need to send this... return ProjectViewModel

How to get Current state or context in Jetpack Compose

拈花ヽ惹草 提交于 2020-03-20 05:48:51
问题 fun createListItem(itemIndex: Int) { Padding(left = 8.dp, right = 8.dp, top = 8.dp, bottom = 8.dp) { FlexRow(crossAxisAlignment = CrossAxisAlignment.Center) { expanded(1.0f) { Text("Item $itemIndex") } inflexible { Button( "Button $itemIndex", style = ContainedButtonStyle(), onClick = { Toast.makeText( this@MainActivity, "Item name $itemIndex", Toast.LENGTH_SHORT ).show() }) } } } } I try to make Toast in a normal way. but I got the error I tried a lot of multiples source but failed. 回答1: You

How to get Current state or context in Jetpack Compose

吃可爱长大的小学妹 提交于 2020-03-20 05:46:20
问题 fun createListItem(itemIndex: Int) { Padding(left = 8.dp, right = 8.dp, top = 8.dp, bottom = 8.dp) { FlexRow(crossAxisAlignment = CrossAxisAlignment.Center) { expanded(1.0f) { Text("Item $itemIndex") } inflexible { Button( "Button $itemIndex", style = ContainedButtonStyle(), onClick = { Toast.makeText( this@MainActivity, "Item name $itemIndex", Toast.LENGTH_SHORT ).show() }) } } } } I try to make Toast in a normal way. but I got the error I tried a lot of multiples source but failed. 回答1: You

how to instantiate ViewModel In AndroidX?

[亡魂溺海] 提交于 2020-03-18 11:27:20
问题 I want to initialize ViewModel in Activity using androidx library I have tried what documentation says but it is not working. the ".of" is not resolved. import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.databinding.DataBindingUtil import androidx.lifecycle.ViewModelProvider import com.example.myapplication.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate

Android Navigation Component Not Displaying Fragment

▼魔方 西西 提交于 2020-03-16 06:22:27
问题 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?,

WorkManager: Why does failed unique work with the “APPEND” ExistingWork strategy not allow more work under the same name?

孤街醉人 提交于 2020-02-23 09:56:44
问题 Let's say we are developing a messaging app where we want to send messages into given conversations where the order of those messages is important in that conversation only, and if the app is put to the background, we want a guarantee that the message will be sent. The WorkManager#beginUniqueWork method seems ideal for this, where the uniqueWorkName will be some conversation id, and ExistingWorkPolicy.APPEND will be used as the work policy to keep the work in the order scheduled. So far in my