Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Extract your class to a different file and make it public </p> <pre><code> public class LogIN extends AsyncTask&lt;Object, Integer, String&gt; { private ILoginListener listener; @Override protected String doInBackground(Object... arg0) { try { this.listener = (ILoginListener) arg0[0]; //You can also send the url in the obj array String theUrl = (String) arg0[1]; String path = "http://www.domain_name.com/app/checkSession.php"; HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); HttpResponse response; JSONObject json = new JSONObject(); try { HttpPost post = new HttpPost(path); json.put("access_token", "123456"); post.setHeader("json", json.toString()); StringEntity se = new StringEntity(json.toString()); se.setContentEncoding((Header) new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(se); response = client.execute(post); /* Checking response */ if (response != null) { InputStream in = response.getEntity().getContent(); String a = convertStreamToString(in); JSONObject jsono = stringToJsonobj(a); String passedStringValue = jsono.getString("result"); if(passedStringValue.equals("1")){ flags=1; //Log.v("TAGG", "Success"); } else { flags=0; //Log.v("TAGG", "Failed !"); } } } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { } return null; } @Override protected void onPreExecute() { super.onPreExecute(); showDialogue("Login Processing", "Loading"); } @Override protected void onProgressUpdate(Integer... progress) { super.onProgressUpdate(progress); } @Override protected void onPostExecute(String result) { listener.logInSessionCheckListener(flag.equals(1)); super.onPostExecute(result); } } </code></pre> <p>Regarding your other question, I normally have an interface for that, something like this:</p> <pre><code> public interface ILoginListener { public void logInSessionCheckListener(SomeNeeded Value); } </code></pre> <p>I implement the interface in the class where i need the postExecute result and in the overriden method you can to what you want with the result of your task. Your class where you user it will look something like this:</p> <pre><code>public class SomeClass implements ILoginListener { //Call it like this from any class: LogIN loginTask = new LogIn(); Object[] someParams = new Object[2]; //add the listener someParams[0] = SomeClass.this //add the url someParams[1] = someUrlString; loginTask.execute(someParams); @Override public void logInSessionCheckListener(SomeNeeded Value){ //do Stuff with your results } } </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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