Posts

Showing posts with the label android

View Binding in Activity and RecyclerView

Image
 You can read what's view binding from the official documentation. I am presenting a TL;DR of how to do it in an Activity and RecyclerView.  This is more of a reference document than a tutorial. This is how the project structure looks like: In the app level build.gradle file inside the android block add the following: buildFeatures { viewBinding = true } And then gradle sync your project. Let me know if you have any comments, question or concerns. Sulav

Implementing Navigation Component in Single Activity Application

 Create a new project with one Activity. class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super .onCreate(savedInstanceState) setContentView(R.layout. activity_main ) } } Create two Fragments(Fragment1 and Fragment2) class Fragment1 : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment return inflater.inflate(R.layout. fragment_1 , container, false ) } } class Fragment2 : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment return inflater.inflate(R.layout. fragment_2 , container, false ) } } Now add dependencies for navigation component and data binding: In app level  build.gradle file,

To install Debug and Release build on a device

Image
On the module level build.gradle file, add the following section: If you have google-services.json file in the app/ directory then create debug and release folders inside app/src as shown below and cut the google-services.json file from the previous location and paste to both the debug and release folder as shown below. Now go to the json file of the debug folder and add .debug to the end of the value of package_name, i.e if originally it was: "package_name": "com.sulav.myapp" change it to "package_name": "com.sulav.myapp.debug" There should be two occurrences of this key, you may have to replace at 2 places. Run the debug built of the app on the device which already has release version of the app, it should work like a charm.