I have an app that starts with a StartupActivity.
That StartupActivity starts the service, like this:
startService(new Intent(StartupActivity.this, SamcomService.class));
At some point, the Service decides to broadcast an Intent, that the StartupActivity reacts to. The Activity, when receiving the INtent, does this:
Intent intent2 = new Intent(StartupActivity.this, DialogActivity.class);
intent2.putExtra("Centrals", list); // list is defined elsewhere
startActivity(intent2);
As you can see, a new Activity is started, and that Activity happens to have Theme.Dialog as Theme. The Dialog shows a list, where the user should select something. At that point, they should be returned to the first Activity, the StartupActivity.
They should also be returned to the first Activity if pressing BACK.
Here is the onCreate code for the DialogActivity:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
final ArrayList<tWorks.Samcom.SICJsonProtocol.Objects.Central> list = (ArrayList<tWorks.Samcom.SICJsonProtocol.Objects.Central>)this.getIntent().getSerializableExtra("Centrals");
// Some more stuff not necessary for this question...
// ....
// ....
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose");
builder.setItems(items2, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
// Do some stuff depending on choice
finish();
}
});
builder.create().show();
}
THe problem is that the entire app, ie all Activitys etc disappar and I am returned to the Home Screen.
If I do not call “finish()”, then I am left with an “overlay” on top of the StartupActivity, and can’t do anything more. If i press BACK, I am returned to the Home Screen.
So, how can I make the DialogActivity to disappear/go away when selecting something from the list or pressing back?
well it should open you startup screen on back. check you manifest. and in manifest check startup activity if there is any android.nohistry=true. just remove it.