0

I'm making a fairly basic app which consists of a custom spinner and an image view. On selecting an item from the spinner, the imageView displays a custom image corresponding to the position of the item in the spinner.

Here's MainActivity.java:

ImageView imageView;
Spinner spinner;
int images[] = {R.drawable.defaultImage,R.drawable.mercury,R.drawable.venus,R.drawable.earth,R.drawable.mars,R.drawable.jupiter,R.drawable.saturn,R.drawable.uranus,R.drawable.neptune,R.drawable.pluto};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    imageView = (ImageView) findViewById(R.id.imageView);
    spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(MainActivity.this,
            R.array.Planets, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(
            new NothingSelectedSpinnerAdapter(
                    adapter,
                    R.layout.contact_spinner_row_nothing_selected,
                    MainActivity.this));
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view,
                                   int pos, long id) {
            ((TextView) parent.getChildAt(0)).setTextSize(20);
            imageView.setImageResource(images[pos]);
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}}

I've used NothingSelectedSpinnerAdapter.java and contact_spinner_row_nothing_selected.xml from this question.

The app builds and runs fine. But here's the problem:

When I select any item in the spinner and press the "Home" button on my phone(with that particular item selected), and then reopen the app after some time(more than 15 minutes or so), the app crashes.

Can someone please help me find a solution for this?

Community
  • 1
  • 1
RGC10
  • 1

0 Answers0