How to use ViewModel in Android
Dependencies dependencies { implementation ‘androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0’ ViewModel class and LiveData
Dependencies dependencies { implementation ‘androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0’ ViewModel class and LiveData
AOSP is the Android Open Spurce Project Architecture Source Code is hosted here: https://android.googlesource.com/platform/manifest Google uses repo (basically a git wrapper written in python) to clone the source code. You can find the instructions here: https://source.android.com/setup/build/downloading Further Reading What is Ninja? What is kapt? Anatomy of a Gradle file
A Snackbar is a replacement for Toasts in Android. Dependency implementation ‘com.google.android.material:material:1.4.0’ Layout A snackbar must be tied to a coordinator layout. If you use fragments the standard layout is FrameLayout which can be directly swapped with: <androidx.coordinatorlayout.widget.CoordinatorLayout Snackbar val snackbar = Snackbar.make( binding.root, “No internet connection! Please enable WiFi or Mobile Data”, Snackbar.LENGTH_INDEFINITE )…
Motivation Sometimes you want to redirect the user from your app to the website for e.g. imprint and data protection info. So it can be helpful to open up a website directly from your app. Implementation In Switch between activities you learned that the standard way of switching between activities is an intent. The same…
In this article I show you how to use timber for logging in your Android App. Timber is built upon Android’s Log class. If you are not yet familiar with logging in Android have a look at Logging in Android
If you want to add another language for your app do the following Create a new folder e.g. app/src/main/res/values-de Add strings.xml into this folder Translate the content The cool thing about translation in android is that you can do it incrementally: when there is no translation for a string resource in a locale Android will…
When you want to interface with any Google API e.g. YouTube from within your Android App, you need to register your app in the developer console. You have to provide a SHA-1 key which can be generated as following: Command line $ chmod u+x gradlew $ ./gradlew signingReport
Sending data private void openVideoActivity(String video) { Intent newActivity = new Intent(this, PlayerActivity.class); newActivity.putExtra(“videoId”, video); startActivity(newActivity); } Retrieving data final String videoID = getIntent().getExtras().getString(“videoID”); In Kotlin it looks like this: val intent = Intent(this, NewActivity::class.java).apply { putExtra(“EXTRA_MESSAGE”, “Test 123”) } startActivity(intent) Retrieving val message = intent.getStringExtra(“EXTRA_MESSAGE”) Further Reading Passing data between fragments using SafeArgs…
Features and Permissions A permission is something an app is allowed to do 🙂 E.g. using the camera, reading location or accessing your contacts. <uses-permission android:name=”android.permission.CAMERA” /> <uses-feature android:name=”android.hardware.camera” android:required=”true” /> Internet Access If your app uses e.g. web-APIs you need internet access. This can be achieved by adding android.permission.INTERNET to your manifest. In this…
From time to time You need to take photos of documents, whiteboards or business cards. Microsoft Office Lens speeds up the process by enhancing the image in an automatic fashion. Recommended by my colleague Jens Dittmar this little helper improved my workday a lot. Let’s see it in action first: Documents Let’s say You have…