The AsyncTask API is deprecated in Android 11. What are the alternatives?

private WeakReference<MyActivity> activityReference; Good riddance that it’s deprecated, because the WeakReference<Context> was always a hack, and not a proper solution. Now people will have the opportunity to sanitize their code. AsyncTask<String, Void, MyPojo> Based on this code, Progress is actually not needed, and there is a String input + MyPojo output. This is actually quite … Read more

How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

The easy way to implement this is to use this attribute to your AndroidManifest.xml where you allow all http for all requests: <application android:usesCleartextTraffic=”true”> </application> But in case you want some more configurations for different links for instance, allowing http for some domains but not other domains you must provide res/xml/networkSecurityConfig.xml file. To do this … Read more

Android Kotlin: Getting a FileNotFoundException with filename chosen from file picker?

You did not receive a file path, you received a Uri. You have to use Uri based APIs such as ContentResolver.openInputStream() to access the contents at that Uri as Android does not grant your app direct File access to the underlying file (it could also be streamed from Google Drive or downloaded directly from the … Read more

Alarm Manager Example

This is working code. It wakes CPU every 10 minutes until the phone turns off. Add to Manifest.xml: … <uses-permission android:name=”android.permission.WAKE_LOCK”></uses-permission> … <receiver android:process=”:remote” android:name=”.Alarm”></receiver> … Code in your class: package yourPackage; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.PowerManager; import android.widget.Toast; public class Alarm extends BroadcastReceiver { @Override public void … Read more

Formatting Double to String? [duplicate]

Understand the Double Data type – it is an approximation of amount and scale. The Following assignment: double d = 2.00000000000f; will generate a value of 1.9999999 at times when printed. What you are seeing here is magnification of that. Double Data types also have a maximum (implementation-dependant) of how many places of significance they … Read more