I'm prototyping a simple app and have one activity with one fragment. The fragment is updated when the user clicks next to rotate through three screens.
I've defined 3 horizontal and vertical relative layouts using dp for the imageview, where each pair of screens has an image included at 50dp*50dp, or 150dp * 150 dp.
The three image ranges from 200k to 400k on disk (no resolution specific versions yet). When I look at my apps memory consumption in ADM I see that my app has somehow run off with 18MB:
1-byte array [byte,bool] Count: 506, Total size:18MB
I thought this might be related to android scaling bitmaps ineffectively, so I moved my assets into drawable-nodpi. This sped up rendering on the emulator (strange given that they were small images to begin with), but didn't impact memory allocation.
To debug, I created a different starting activity, not loading the activity with images until a button is pressed. I was hoping I could use the allocation tracker to hunt down issue. Once again, at start time, the app still uses 18MB of memory, so I couldn't figure out where it's being allocated.
Any ideas what might be going on?
Adding some code as requested as well:
1) One of the layout files:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:text="@string/FRE_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:editable="false"
android:autoText="false"
android:clickable="false"
android:focusable="false"
android:enabled="true"
android:padding="10dp"
/>
<ImageView
android:id="@+id/freImage1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/fre_1" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/imageButton"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/right_arrow" />
<Button
android:id="@+id/buttonGetStarted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Get_started"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:onClick="LoadLogin" />
</RelativeLayout>
The Activity is based on the standard template, with the core parts being:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intro_main); //this loads the xml layout file
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
Log.i(myApp, "IntroMain:OnCreate");
}
Swapping Logic in the FRE fragment:
public static FREFragment newInstance(int sectionNumber) {
FREFragment fragment = new FREFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public FREFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mNum = getArguments().getInt(ARG_SECTION_NUMBER); //figure out which page we're on
View rootView;
if (mNum == 1) {
rootView = inflater.inflate(R.layout.fragment_fre1, container, false);
Log.i(myApp, "IntroMain:onCreateView:Started:1");
} else if (mNum == 2) {
rootView = inflater.inflate(R.layout.fragment_fre2, container, false);
Log.i(myApp, "IntroMain:onCreateView:Started:2");
} else {
rootView = inflater.inflate(R.layout.fragment_fre3, container, false);
Log.i(myApp, "IntroMain:onCreateView:Started:3");
}
return rootView;
}