新活动没有出现任何错误

时间:2016-12-21 10:05:51

标签: android networking android-view android-networking

我有一个onClickListener,它正在通过json等发送数据,但我想在此之后打开新的活动。这是代码的一部分:

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

我要打开的新活动我实现了:

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

哪里有问题?数据被发送,我正在成功举杯,什么都没有。

1 个答案:

答案 0 :(得分:4)

根据您粘贴的代码,您似乎并没有调用switchBack()方法来开展您的活动,除非它在别处被调用。

您可以通过设置断点并调试应用来进行检查。这是https://developer.android.com/studio/debug/index.html#breakPoints

的方式