I have a problem with an app of mine and I do not know what to do to fix it. I'm new to Android and do not understand java.
The app consists of multiple pages containing lists, all with a spinner to navigate between those pages. You select in item in the spinner and the app opens that page. As well as hopping between pages there is, in the spinner, an option to 'Exit App'.
Page hopping works no problem. The problem I have is with the 'Exit App' code. When I exit the app by pressing the home key on my device, or by tapping Exit App (from the spinner) and then restart the app, it opens not on the dashboard, but on the page I was last viewing. To resolve this issue, I need to long press the device's home key and then swipe the app from the recently used list.
Is there a way so that when I exit the app by pressing the home key on the device, or by tapping Exit App from the spinner and then restart the app, it does open on the dashboard?
Can anyone help?
Thanks.
The String Code...
<string-array name="TheList">
<item>Tap Here For List…</item>
<item>Cheese</item>
<item>Planets</item>
<item>Cars</item>
<item><b>Back To Dashboard…</b></item>
<item><b>EXIT APP</item>
</string-array>
The case numbers (1-4) in the code below are the pages that open with a spinner item selection.
Case 5 exits the app. I assume there is an error in the code that prevents the app from restarting on the dashboard.
The java code...
package com.example.acer.MyKitList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
public class Carrying extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page1);
// Spinner element & Spinner click listener
Spinner Spinner = (Spinner) findViewById(R.id.Spinner1);
Spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View view, int position, long row_id) {
switch (position) {
case 1:
Intent a = new Intent(Dashboard.this, Cheese.class);
startActivity(a);
finish();
break;
case 2:
Intent b = new Intent(Dashboard.this, Planets.class);
startActivity(b);
finish();
break;
case 3:
Intent c = new Intent(Dashboard.this, Cars.class);
startActivity(c);
finish();
break;
case 4:
Intent d = new Intent(Dashboard.this, Dashboard.class);
startActivity(d);
finish();
break;
case 5:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
System.exit(0);
finish();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
@Override
public void onBackPressed() {
finish();
}
}