0

我正在创建一个作为售票系统的应用程序。在结帐页面(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 代码,但随后继续运行并且从未真正启动该活动。

谢谢!

4

4 回答 4

1

开始活动的正确方法如下:

Intent intent = new Intent(PaymentScreen.this, EventList.class);
startActivity(intent);
于 2012-06-19T06:41:53.100 回答
0

尝试这个

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

安装的

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();

如果你没有提到这个

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

在您的清单中然后声明它。

于 2012-06-19T06:43:32.630 回答
0

代替PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, CityList.class));

尝试:

PaymentScreen.this.startActivity(new Intent(PaymentScreen.this, CityList.class));
于 2012-06-19T06:27:02.017 回答
0

确保你已经在 minifest 中定义了它。

最好打电话

 context.startActivity()

内测

于 2016-01-13T05:49:03.837 回答