我正在创建一个作为售票系统的应用程序。在结帐页面(PaymentScreen 活动)上执行检查以确保客户已登录其帐户,如果未登录,则在继续结帐之前将其重定向到登录。
当我检查客户是否已登录时,代码正确验证客户未登录,然后执行该 if 函数(我可以从 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();
}
}
日志猫:
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 代码,但随后继续运行并且从未真正启动该活动。
谢谢!