Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.AsyncTask;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.protocol.HTTP;
- import org.apache.http.util.EntityUtils;
- import java.io.IOException;
- public class GetOcitanja extends AsyncTask<Object, Void, String> {
- Activity _context;
- String _str_mesg;
- String _str_naslov;
- public ProgressDialog progress;
- public GetOcitanja(Activity context, String str_naslov, String str_message){
- this._context = context;
- this._str_naslov = str_naslov;
- this._str_mesg = str_message;
- }
- @Override
- protected void onPreExecute() {
- //super.onPreExecute();
- progress = ProgressDialog.show(_context, _str_naslov,
- _str_mesg, true);
- progress.show();
- }
- @Override
- protected void onPostExecute(String s) {
- //super.onPostExecute(s);
- progress.dismiss();
- }
- @Override
- protected String doInBackground(Object... params) {
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- HttpClient httpClient = new DefaultHttpClient();
- HttpGet httpRequest = new HttpGet(Config.url_get_ocitanja_async_taks);
- String odg="";
- try {
- HttpResponse response = httpClient.execute(httpRequest);
- HttpEntity entity = response.getEntity();
- odg = EntityUtils.toString(entity, HTTP.UTF_8);
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return odg;
- }
- GetOcitanja asyncTask=new GetOcitanja(Fill_in_phone.this, "a","b");
- asyncTask.execute();
- String response="";
- try {
- response= asyncTask.get();
- } catch (InterruptedException e1) {
- e1.printStackTrace();
- } catch (ExecutionException e1) {
- e1.printStackTrace();
- }
- }
- Activity _context; // Change type of _context to Activity
- public GetOcitanja(Activity context, String str_naslov, String str_message){
- this._context = context;
- ....
- }
- private ProgressDialog pdia;
- @Override
- protected void onPreExecute(){
- super.onPreExecute();
- pdia = new ProgressDialog(yourContext);
- pdia.setMessage("Loading...");
- pdia.show();
- }
- @Override
- protected void onPostExecute(String result){
- super.onPostExecute(result);
- pdia.dismiss();
- }
- public GetOcitanja(Activity context, String str_naslov, String str_message){
- this._context = context;
- this._str_naslov = str_naslov;
- this._str_mesg = str_message;
- progressDialog = new ProgressDialog(_context);
- progressDialog.setTitle("Progress");
- }
- response= asyncTask.get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement