0
喜下一從那裏開始我想打電話給一個活動的決定哪個是下一個活動啓動後,對話框完成,如:如何決定哪些活動會後的Android
Intent dialog_intent = new Intent(_parent, MyActivityA.class);
dialog_intent.putExtra(MyActivityA.EXTRA_PARENT, MyActivityB.class);
我得到額外的像這樣的MyActivityA的OnCreate:
Type _parent = null; // this is a class variable
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if (bundle != null) {
Set<String> keys = bundle.keySet();
Iterator<String> it = keys.iterator();
while (it.hasNext())
{
String key = it.next();
if(key.equals(EXTRA_PARENT))
_parent = (Type)bundle.get(EXTRA_PARENT);
}
}
在finishDialog方法我這樣做:
public void finishDialog(View v)
{
try
{
Intent intent = null;
if(_parent != null && _parent instanceof Activity)
{
intent = new Intent(this, _parent.getClass());
}
else
{
intent = new Intent(this, DefaultActivity.class);
}
if(intent != null)
{
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
finish();
}
2問題:
爲什麼_parent instaneof Activity不起作用。我認爲MyActivity是繼承活動 的類型試圖啓動該活動不起作用。但如果我把
new Intent(this,MyActivityB.class);
它的工作原理!我究竟做錯了什麼。有沒有其他方法可以做到這一點
是的,我想過一個更加動態的解決方案....當然這會工作,但我必然要實現的選項,並不能拋出一些新的對話框...... – 2015-03-03 07:43:33
你可以編寫一個Util函數,它會給你基於整數的活動類名,你的邏輯將在一個地方,如果你需要顯示另一個活動,你只需要更新該函數。 – 2015-03-03 07:51:59
是的,你是對的,但我仍然不想更新任何功能,因爲這個庫不應該改變! – 2015-03-03 07:58:51