Stephen
Stephen

Reputation: 225

Android StartActivity run but nothing happens

I am creating an app that is a ticket sales system. On the checkout page (the PaymentScreen activity) a check is performed to ensure that the customer is signed into their account, and if they are not, they are redirected to log in before continuing to checkout.

When I check to see if a customer is signed in, the code correctly verifies that the customer is not signed in, and then executes that if function (I can tell from LogCat), but the activity is never launched and the code continues to execute.

Any help would be appreciated - I can't seem to figure this one out.

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>

So clearly from the LogCat the program recognizes that the customer is null and runs over the StartActivity code, but then continues to run and never actually starts that activity.

Thanks!

Upvotes: 0

Views: 2328

Answers (4)

joe
joe

Reputation: 639

make sure you had defined it in minifest..

it's better to call

 context.startActivity()

insde

Upvotes: 0

Siddhesh
Siddhesh

Reputation: 1380

try this

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

insted of

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

you can do it like

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

if u havnt mentioned this

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

in your manifest then declare it.

Upvotes: 0

Arun George
Arun George

Reputation: 18592

The right way to start activity is as follows:

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

Upvotes: 1

Shrikant Ballal
Shrikant Ballal

Reputation: 7087

Instead of PaymentScreen.this.startActivity(new Intent().setClass(PaymentScreen.this, CityList.class));

try:

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

Upvotes: 0

Related Questions