Strange OutOfMemory issue while loading an image to a Bitmap object

To fix the OutOfMemory error, you should do something like this: BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 8; Bitmap preview_bitmap = BitmapFactory.decodeStream(is, null, options); This inSampleSize option reduces memory consumption. Here’s a complete method. First it reads image size without decoding the content itself. Then it finds the best inSampleSize value, it should be … Read more

Is there a way to get the source code from an APK file?

Simple way: use online tool https://www.decompiler.com/, upload apk and get source code. Procedure for decoding .apk files, step-by-step method: Step 1: Make a new folder and copy over the .apk file that you want to decode. Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it. … Read more

Activity restart on rotation Android

Using the Application Class Depending on what you’re doing in your initialization you could consider creating a new class that extends Application and moving your initialization code into an overridden onCreate method within that class. public class MyApplicationClass extends Application { @Override public void onCreate() { super.onCreate(); // TODO Put your application initialization code here. … Read more

How do I pass data between Activities in Android application?

In your current Activity, create a new Intent: String value=”Hello world”; Intent i = new Intent(CurrentActivity.this, NewActivity.class); i.putExtra(“key”,value); startActivity(i); Then in the new Activity, retrieve those values: Bundle extras = getIntent().getExtras(); if (extras != null) { String value = extras.getString(“key”); //The key argument here must match that used in the other activity } Use this … Read more

How can you get the build/version number of your Android application?

If you’re using the Gradle plugin/Android Studio, as of version 0.7.0, version code and version name are available statically in BuildConfig. Make sure you import your app’s package, and not another BuildConfig: import com.yourpackage.BuildConfig; … int versionCode = BuildConfig.VERSION_CODE; String versionName = BuildConfig.VERSION_NAME; No Context object needed! Also make sure to specify them in your … Read more

Android 8: Cleartext HTTP traffic not permitted

According to Network security configuration – Starting with Android 9 (API level 28), cleartext support is disabled by default. Also have a look at Android M and the war on cleartext traffic Codelabs explanation from Google Option 1 – First try hitting the URL with https:// instead of http:// Option 2 – Create file res/xml/network_security_config.xml … Read more