如何传递从url获取两个id并使用共享首选项将其传递给其他类

Siv*_*r S 0 string url android parameter-passing sharedpreferences

http://example/map.php?cust_id = 1&store_id = 2,在onclick链接期间从url获取cust_id和store_id并将其保存在另一个共享首选项中.我从其他类调用这两个id并希望将这两个id发送到其他url但是id的值没有上传到该url,如果仅传递cust_id意味着一切正常,而传递两个值则无效.这个概念的新手请帮助我.

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        CharSequence urlstring1="cust_id";
        CharSequence urlstring2="store_id";
        String[] details = url.split("[?]");
        String[] strdetails =details[1].split("&");
        String strcust_id = strdetails[1];
        String strstore_id= strdetails[1];

        if (url.contains(urlstring1)& url.contains(urlstring2)){
            SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString("Customer", strcust_id).putString("Store", strstore_id);
            editor.commit();

            AboutusFragment fragment2 = new AboutusFragment();
            FragmentManager fragmentManager = getFragmentManager();
            android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container, fragment2);
            fragmentTransaction.commit();
            return false;
        }else{
            return super.shouldOverrideUrlLoading(view, url);
        }
    }
Run Code Online (Sandbox Code Playgroud)

在下一堂课

if(CheckNetwork.isInternetAvailable(getContext().getApplicationContext())) //returns true if internet available
    {
        SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        String strquerystring=settings.getString("Customer","")+settings.getString("Store","");
        String strs = "http://example/bookappointment.php?" + strquerystring;
        web.setWebViewClient(new myWebClient());
        web.getSettings().setJavaScriptEnabled(true);
        web.loadUrl(strs);
    }
Run Code Online (Sandbox Code Playgroud)

ρяσ*_*я K 5

可能在这里:

String strcust_id = strdetails[1];
String strstore_id= strdetails[1];
Run Code Online (Sandbox Code Playgroud)

导致问题的行,因为strdetails[1]为两个变量分配相同的值.

而不是String.split用于从url获取参数.用于android.net.Uri使用以下名称从URL获取两个参数:

Uri uriURL=Uri.parse(url);
String strcust_id=uriURL.getQueryParameter("cust_id");
String strstore_id =uriURL.getQueryParameter("store_id");
Run Code Online (Sandbox Code Playgroud)

现在保存strcust_idstrstore_idSharedPreferences.并确保android.net.Uri在课堂上导入包.