2012-06-19 40 views
0

我正在創建一個應用程序,它是一個門票銷售系統。在結賬頁面(PaymentScreen活動)執行檢查以確保客戶登錄到他們的賬戶,如果他們沒有登錄,他們將被重定向登錄,然後再繼續結賬。Android StartActivity運行但沒有任何反應

當我檢查客戶是否登錄時,代碼正確驗證客戶沒有登錄,然後執行該功能(我可以從LogCat中得知),但該活動永遠不會啓動,並且代碼繼續執行。

任何幫助將不勝感激 - 我似乎無法找出這一個。

PaymentScreen.java:

public class PaymentScreen extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.paymentscreen); 

    if(Singleton.getInstance().selected_city == null) { 
     PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, CityList.class)); 
    } 
    if(Singleton.getInstance().selected_venue == null) { 
     PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, VenueList.class)); 
    } 
    if(Singleton.getInstance().selected_event == null) { 
     PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, EventList.class)); 
    } 
    if(Singleton.getInstance().customer == null) { 
     PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, LoginScreen.class).putExtra("sendToActivity", "PaymentScreen")); 
     Log.d("LineBouncer", "in if statement and (customer == null) is true"); 
    } 
    if(Singleton.getInstance().customer == null) { 
     Log.d("LineBouncer", "customer is null"); 
    } 
    new GetPrepurchaseId().execute(); 
} 
} 

的logcat:

06-19 02:10:22.972: D/LineBouncer(3102): in if statement and (customer == null) is true 
06-19 02:10:22.972: D/LineBouncer(3102): customer is null 

的AndroidManifest.xml:

<activity android:name=".CityList" android:label="@string/app_name"></activity> 
    <activity android:name=".LoginScreen" android:label="@string/app_name"></activity> 
    <activity android:name=".CreateAccount" android:label="@string/app_name"></activity> 
    <activity android:name=".VenueList" android:label="@string/app_name"></activity> 
    <activity android:name=".EventList" android:label="@string/app_name"></activity> 
    <activity android:name=".EventDetails" android:label="@string/app_name"></activity> 
    <activity android:name=".PaymentScreen" android:label="@string/app_name"></activity> 
    <activity android:name=".OrderHistory" android:label="@string/app_name"></activity> 
    <activity android:name=".PassView" android:label="@string/app_name"></activity> 

因此,從logcat的程序識別清楚,客戶是零和運行通過StartActivity代碼,但隨後繼續運行並從未實際啓動該活動。

謝謝!

+0

你失蹤這件事情<活動機器人:名字=」 .CityList「android:label =」@ string/app_name「>在您的清單文件中 – KMI

+0

抱歉 - th實際上在那裏,我只是沒有發佈在上面的代碼片段中。我已更新以反映這一點。 – Stephen

回答

1

開始活動的正確方法如下:

Intent intent = new Intent(PaymentScreen.this, EventList.class); 
startActivity(intent); 
+0

謝謝你 - 我已更新我的代碼以使用此方法開始活動。但是,問題仍然存在於代碼中,然而,當我希望它立即轉到這個新的活動而不繼續時,startActivity方法後面的代碼仍然繼續運行。 – Stephen

+0

只需在「if」塊中放置一個'return',它就不會落下其他語句。或者簡單地使用'if','else if'和'else'來使所有的塊互相獨立 –

+0

啊,謝謝。 我假設startActivity方法的默認行爲是立即啓動活動並且不繼續執行。你知道爲什麼代碼在默認調用startActivity之後繼續執行嗎?這似乎對我來說很直觀。 – Stephen

0

而不是PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, CityList.class));

嘗試:

PaymentScreen.this.startActivity(new Intent(PaymentScreen.this, CityList.class)); 
0

試試這個

startActivity(new Intent(PaymentScreen.this, LoginScreen.class).putExtra("sendToActivity", "PaymentScreen")); 

insted的的

PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, LoginScreen.class).putExtra("sendToActivity", "PaymentScreen")); 

,你可以不喜歡它

Intent in; 
if(Singleton.getInstance().selected_city == null) { 
     in=new Intent(PaymentScreen.this, CityList.class); 
     startActivity(in); 
    } 
    if(Singleton.getInstance().selected_venue == null) { 
     in=new Intent(PaymentScreen.this, VenueList.class); 
     startActivity(in); 

    } 
    if(Singleton.getInstance().selected_event == null) { 
     in=new Intent(PaymentScreen.this, EventList.class); 
     startActivity(in); 
    } 
    if(Singleton.getInstance().customer == null) { 
     in=new Intent(PaymentScreen.this, LoginScreen.class); 
     in.putExtra("sendToActivity", "PaymentScreen"); 
     startActivity(in); 
     Log.d("LineBouncer", "in if statement and (customer == null) is true"); 
    } 
    if(Singleton.getInstance().customer == null) { 
     Log.d("LineBouncer", "customer is null"); 
    } 
    new GetPrepurchaseId().execute(); 

如果u havnt提到這個

<activity android:name=".CityList" android:label="@string/app_name"></activity> 
您清單

則聲明。

0

確保您已在minifest定義它..

它更好地調用

context.startActivity()

insde

相關問題