I’ve been using no-dpi drawables in my application for tiled backgrounds and it works great, but it fails when I start another activity in the onCreate of my main-activity.
This behaviour does not occur in an emulator which leads me to think it’s something device-related. I’m using a Samsung Galaxy Note to test this on (Android 2.3.6).
Reproduction
For debugging purposes I’ve created a new project, added the tile.png to the drawable-nodpi folder, created bg_tile.xml in the drawable folder and set the background in the main.xml layout file to “@drawable/bg_tile”
So far so good:
https://i.stack.imgur.com/FGrr1.png
Now I’ve copied the main.xml to secondary.xml, and created another activity which uses secondary.xml.
To open the secondary activity, I’ve added it to the onCreate of the main activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent activityIntent = new Intent(this, NoDPISecondaryActivity.class);
this.startActivity(activityIntent);
}
The secondary activity should be shown with the same tiled background as in the main activity, but instead it scales the drawable:
https://i.stack.imgur.com/9Xwwp.png
What next?
It this just something Samsung related where I’ve got to learn to live with, or has anyone got a clue on what’s going on and how to fix this behaviour?
My observations:
-
Pressing “back” returns to the main activity which shows the tiled background correctly.
-
Also, the secondary activity shows correctly when I initiate it using a button with an OnClickListener
Contents of the bg_tile.xml file:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tile"
android:tileMode="repeat" />
After updating the Galaxy Note to Android 4.0 this is resolved. Looks like it was a vendor/device-specific bug.