New Activity not appearing without any error

89 views Asked by At

I've got a onClickListener which is sending data by json etc, but I want to after that, open new activity. Here is a part of code:

btnEnter.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                onLoginAttempt();
            }
        });
        /*txtInvite.setText(Html.fromHtml(PreferenceConnector.readString(aiContext, 
                PreferenceConnector.INVITETEXT, "")));*/

        HashMap<String, String> hash    =   new HashMap<String, String>();
        hash.put("user_id", PreferenceConnector.readString(aiContext, PreferenceConnector.USERID,""));
        hash.put("first_name", PreferenceConnector.readString(aiContext, PreferenceConnector.FIRST_NAME,""));
        hash.put("last_name", PreferenceConnector.readString(aiContext, PreferenceConnector.LAST_NAME,""));
        hash.put("email",PreferenceConnector.readString(aiContext, PreferenceConnector.PAYPAL_EMAIL,""));
        hash.put("offer_id",getArguments().getString("offerid"));

        //callWebService(GlobalVariables.REDEEM_OFFER, hash);
    }
}

String strUserName, strPassword,strEmail;
private void onLoginAttempt() {
    int response    = 0;
    response        = gd.emptyEditTextError(
            new EditText[]{first_nameEdit,last_nameEdit,email_editText},
            new String[]{ getResources().getString(R.string.error_register_empty_first_name),
                    getResources().getString(R.string.error_register_empty_last_name),
                    getResources().getString(R.string.error_register_empty_email)
            });

    if (! GlobalData.isEmailValid(email_editText.getText().toString().trim())) {
        response++;
        email_editText.setError(getResources().getString(R.string.error_login_invalid_email));
    }

    if(response == 0) {
        strUserName         = first_nameEdit.getText().toString().trim();
        strPassword         = last_nameEdit.getText().toString().trim();
        strEmail            = email_editText.getText().toString().trim();


        /*HashMap<String, String> hash  =   new HashMap<String, String>();
        hash.put("user_id", PreferenceConnector.readString(aiContext, PreferenceConnector.USERID,""));
        hash.put("first_name", PreferenceConnector.readString(aiContext, PreferenceConnector.FIRST_NAME,""));
        hash.put("last_name", PreferenceConnector.readString(aiContext, PreferenceConnector.LAST_NAME,""));
        hash.put("email",PreferenceConnector.readString(aiContext, PreferenceConnector.PAYPAL_EMAIL,""));
        hash.put("offer_id",getArguments().getString("offerid"));*/


        //callWebService(GlobalVariables.REDEEM_OFFER, hash);

        String[] keys       = {"user_id","first_name", "last_name", "email", "offer_id"};
        String[] value      = {PreferenceConnector.readString(aiContext, PreferenceConnector.USERID,""),strUserName, strPassword, strEmail,getArguments().getString("offerid")};

        HashMap<String, String> hash    =   new HashMap<String, String>();
        for (int i = 0; i < keys.length; i++) {
            System.out.println(keys[i]+ "......." + value[i]);
            hash.put(keys[i], value[i]);
        }

        if (gd.isConnectingToInternet()) {
            callWebService(GlobalVariables.REDEEM_OFFER, hash);
        }else {
            GlobalData.showToast(getResources().getString(R.string.error_no_internet), aiContext);
        }
    }
}

private void callWebService(String postUrl, HashMap<String, String> hash) {
    WebService webService   =   new WebService(aiContext, "", postUrl, hash, this, WebService.POST);
    webService.execute();
}

@Override
public void onWebServiceActionComplete(String result, String url) {
    System.out.println(result+".........jsonresponse....."+url);

    try {
        JSONObject json = new JSONObject(result);
        String str_RESULT   = json.getString(TAG_RESULT);
        String str_Message  = json.getString(TAG_MESSAGE);

        if (str_RESULT.equals("YES")) {
            GlobalData.showToast(getResources().getString(R.string.message_redeem_success), aiContext);
            JSONObject Data_obj         = json.getJSONObject(TAG_DATA);
            String str_user_points      = Data_obj.getString(DailyRewardFragment.TAG_USER_POINTS);


            PreferenceConnector.writeInteger(aiContext, PreferenceConnector.WALLETPOINTS, 
                    Integer.parseInt(str_user_points));
            FragEarnCredits.onUpdateView(aiContext);
            ViewRewardsFragment.onUpdateView(aiContext);
            InviteFriendsFragment.onUpdateView(aiContext);
            ConnectSocialFragment.onUpdateView(aiContext);

        } else {
            GlobalData.showToast(str_Message, aiContext);
        }
    } catch (JSONException e){
        e.printStackTrace();
    }
}
private void switchBack() {
    if (getActivity() == null)
        return;
    if (getActivity() instanceof ActivityMainWallet) {
        ActivityMainWallet mActivity = (ActivityMainWallet) getActivity();
        mActivity.customizeActionBar();
        mActivity.switchBack();
    }
    Intent i = new Intent(getApplicationContext(),Zamawiam.class);
    startActivity(i);
}
}

The new activity I want to open I implemented with:

Intent i = new Intent(getApplicationContext(),Zamawiam.class);
startActivity(i);

Where is a problem? Data is sent, I'm getting success toast and nothing.

1

There are 1 answers

0
Xavi Rigau On

From the code you pasted it seems like you're not calling the switchBack() method which is where you start your activity, unless it's called elsewhere.

You can check by setting a breakpoint and debug the app. Here's how https://developer.android.com/studio/debug/index.html#breakPoints