新活动没有出现任何错误

问题描述 投票:-1回答:1

我有一个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);

哪里有问题?数据发送,我成功举杯而没有。

android networking android-view android-networking
1个回答
4
投票

从您粘贴的代码看来,您似乎没有调用switchBack()方法,这是您开始活动的地方,除非在其他地方调用它。

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

© www.soinside.com 2019 - 2024. All rights reserved.