我有一個StartupActivity啓動的應用程序。服務廣播到開始新的活動作爲對話的活動 - 如何返回到第一個活動?
這StartupActivity啓動該服務,像這樣:
startService(new Intent(StartupActivity.this, SamcomService.class));
在某一點上,服務決定播出的意圖,即StartupActivity反應。活動中,接收的意圖時,做到這一點:
Intent intent2 = new Intent(StartupActivity.this, DialogActivity.class);
intent2.putExtra("Centrals", list); // list is defined elsewhere
startActivity(intent2);
正如你可以看到,一個新活動啓動,而這一活動恰好有Theme.Dialog爲主題。對話框顯示一個列表,用戶應該選擇一些內容。到那時,他們應該返回到第一個Activity,即StartupActivity。 如果按下BACK,它們也應該返回到第一個Activity。
下面是DialogActivity中的onCreate代碼:
@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();
}
的問題是,整個應用程序,即所有Activitys等disappar,我返回到主屏幕。
如果我不叫「完成()」,然後我留下的StartupActivity頂部的「疊加」,不能做什麼。如果我按BACK,我會返回到主屏幕。
所以,我怎樣才能使DialogActivity消失/從列表中選擇某事或按下回來的時候走?
啊,原來如此。完全錯過了那一個。 Thx =) – Ted
歡迎:) – Zohaib