Android: run task in background

 

[java]

package de.clarisweb.android.downloadwebcontent;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
public class DownloadTask extends AsyncTask {

@Override
protected String doInBackground(String… strings) {

Log.i("URL", strings[0]);

return "done !";
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

DownloadTask task = new DownloadTask();
String result=null;

try {

result = task.execute("https://cipv6.de").get();

} catch (Exception e) {

e.printStackTrace();
}

Log.i ("Result", result);

}
}

[/java]

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.