Note that there are some explanatory texts on larger screens.

plurals
  1. POCall JSON from another activity
    primarykey
    data
    text
    <p>I have one problem. I have an app where you can vote for someone you like. You can vote just one time per day. I save that day when user votes with SharedPreferences, so user can't vote one more time that day. Everything is working okay. I create another activity and from that activity I know user's choice. That means, I know for who user want to vote. My question is: how can I get user's sharedpreferences(day when user vote last time), write it to SharedPreferences (that Vote Activity would know that i choose someone) and do i have to copy the same code from vote Activity to second Activity or I can use my Vote Activity from some place of code? My code with saving Preferences and calling JSON:</p> <pre><code>private void savePreferences(String key, int value) { SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this); Editor editor = sharedPreferences.edit(); editor.putInt(key, value); editor.commit(); } class AttemptLogin extends AsyncTask&lt;String, String, String&gt; { @Override protected void onPostExecute(String file_url) { // TODO Auto-generated method stub super.onPostExecute(file_url); pDialog.dismiss(); } @Override protected String doInBackground(String... args) { // TODO Auto-generated method stub String pos = pos1.toString(); Log.i("12", pos); int success; try { List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;(); params.add(new BasicNameValuePair("pos", pos)); Log.d("request!", pos); JSONObject json = jsonParser.makeHttpRequest(VOTE_URL, "POST", params); success = json.getInt(TAG_SUCCESS); if (success == 1) { Log.d("Successful!", json.toString()); Intent i = new Intent(Vote.this, MainActivity.class); finish(); startActivity(i); } else { Log.d("Failure!", json.toString()); } } catch (JSONException e) { e.printStackTrace(); } return null; } @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); pDialog = new ProgressDialog(Balsuok.this); pDialog.setMessage("Voting..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload