我正在创建一个销售系统的应用程序。在结帐页面(PaymentScreen活动)上,将执行检查以确保客户已登录其帐户,如果不是,则会在继续结帐前将其重定向以登录。
当我检查客户是否已登录时,代码会正确验证客户是否未登录,然后执行该功能(我可以从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 :(得分:1)
开始活动的正确方法如下:
Intent intent = new Intent(PaymentScreen.this, EventList.class);
startActivity(intent);
答案 1 :(得分:0)
而不是PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, CityList.class));
尝试:
PaymentScreen.this.startActivity(new Intent(PaymentScreen.this, CityList.class));
答案 2 :(得分: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>
在你的清单中然后声明它。
答案 3 :(得分:0)
确保你已经在minifest中定义了它。
最好拨打
context.startActivity()
insde