I'm getting a memory related crash in an Android app I'm making. This is where I've narrowed the crash down to:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("flow", "onCreate");
setContentView(R.layout.activity_today);
setGroup();
mPager = (ViewPager) findViewById(R.id.today_activity_relative);
mPagerAdapter = new MyAdaptor(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
PageChanger changer = new PageChanger();
mPager.addOnPageChangeListener(changer);
mPager.setCurrentItem(position);
ImageView icon = new ImageView(this);
icon.setImageResource(R.drawable.ic_action_new);
FloatingActionButton actionButton = new FloatingActionButton.Builder(this).setContentView(icon).setBackgroundDrawable(R.drawable.action_button_selector).build(); //this is the culprit
actionButton.setOnClickListener(this);
}
If I comment out the top two lines of the bottom group of code (and remove the setContentView method of the builder so it still runs), I still get the crash. But I comment out that one noted line (and the listener), it works fine.
This is the library I'm using to create the floating action button. The only modification I've made is calling my own drawable as seen in the code above, but I still get the crash when I use the default one in the library.
The crash occurs in a single activity, which contains a ViewPager that swipes between fragments that read from a database. The actual crash Logcat points to the database cursor as not having enough memory, and it occurs when swiping between pages often enough. The memory graph in AS slowly fills up to 16MB then the app unexpectedly quits. Whereas if I have the line in question commented out, I never go above 4-5MB.
I'm not asking anyone to debug this library for me, but I'd like get a better understanding of just what's going on here. It's very confusing to me. This is all taking place in onCreate, in an activity that never loses focus (and according to the logs this code only executes a single time).
Edit: Link to the Logcat and AS memory graphs screenshots.