Sometimes, we need our TextView change its text size according to the content put in it. But, Android didn’t have much support of it until Android O. And then Android Support library got this feature. Let’s see how it all works. First, you have to add the support library v26 or more in your build.gradle file. implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:support-v4:26.1.0' Although, it has been introduced in Android Oreo, but through using support library, this feature is backward compatible upto the Android 4.

Continue reading

When debugging apps, we sometimes start putting logging statements all over the code to figure out what’s going on. class MainActivity : AppCompatActivity() { lateinit var retrofit: Retrofit override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) setupToolbar() Log.d("MyApp", "Toolbar Set") initRetrofit() Log.d("MyApp", "Retrofit Initialized") var myButton = findViewById<Button>(R.id.search_close_btn) myButton.setOnClickListener { Log.d("MyApp", "My Button Clicked") } Log.d("MyApp", "Activity Creation Done!") } } That works, but it happens that we forget to remove the logs before committing, and they either get flagged in the code review, or they’re still there when we release.

Continue reading

Although RecyclerView has a very good and smooth scrolling built-in, but when you put into any ScrollView, then your RecyclerView’s scrolling will not work. For example, <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <android.support.v7.widget.RecyclerView android:id="@+id/listRecyclerView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/_10sdp" tools:listitem="@layout/activity_type_item_layout"/> </LinearLayout> </ScrollView> Now, the RecyclerView will not scroll. To fix that, you will have to use NestedScrollView instead of ScrollView like this: <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <android.support.v7.widget.RecyclerView android:id="@+id/listRecyclerView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="@dimen/_10sdp" tools:listitem="@layout/activity_type_item_layout"/> </LinearLayout> </android.

Continue reading

A very common task in any android app is to hit any web service call and fetch some data from server. Google have always recommended to perform such heavy or time consuming calls in background thread, as if performed in main thread, these can block the UI and make the app irresponsive Traditionaly, developers use AsyncTask for these sorts of computations. But working with AsyncTask is not only complex and lengthy, but also very frustrating.

Continue reading

When developers need to integrate push notifications in their Android apps, the first thing comes in mind is Firebase Notifications or Firebase Messaging. But when they integrate, there are few common issues which they stuck into. One of those common issues is that the applications doesn’t get push notifications. There are multiple reasons such as Unregistered device token or app is killed or Android Oreo’s doze mode is on etc.

Continue reading

There are times when there’s multiple lines of operations on the same object, and we do it by calling myObject instance everytime we do any operation. This makes our code repetitive and makes it look bad and ugly. For example, when we put different values in the Intent, we do it like this: var intent = Intent() intent.putExtra("myInt", 0) intent.putExtra("myBool", false) intent.putExtra("myString", "hello string") startActivity(intent) And when we receive this Intent in any other Activity, then we get all the values like this:

Continue reading

Launching activities in android apps is a common task and different developers use different approaches. Some use the traditional ways of creating Intent bundles and passing them in startActivity() methods along side the Intents. But, with Kotlin DSL and writing a handful of extension methods, this can become a lot more easier and readable than the traditional ways. Let’s look at the typical traditional way of starting another activity var intent = Intent(myActivity, TargetActivity::class) myActivity.

Continue reading

Author's picture

Wajahat Karim

Android Developer. UI/UX Designer. Blogger. Writer. Wantrepreneur. GitHub Geek. Tea Lover

Senior Android Developer

Karachi, Pakistan