Answer the question
In order to leave comments, you need to log in
How to switch to a new activity and process the process at the same time?
There is such an example
public class MainActivity extends AppCompatActivity {
private Button button;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
textView = (TextView)findViewById(R.id.textView1);
}
public void ClickMe(View v) {
MyTask mt = new MyTask();
mt.execute();
//Intent intent = new Intent(MainActivity.this, Parsed.class);
//startActivity(intent);
}
class MyTask extends AsyncTask<Void, Void, Void> {
String html;//Тут храним значение заголовка сайта
@Override
protected Void doInBackground(Void... params) {
Document doc = null;//Здесь хранится будет разобранный html документ
try {
//Считываем заглавную страницу http://harrix.org
doc = Jsoup.connect("http://habrahabr.ru").get();
} catch (IOException e) {
//Если не получилось считать
e.printStackTrace();
}
//Если всё считалось, то вытаскиваем из считанного html документа всё
if (doc!=null)
html = doc.html();
else
html = "Ошибка";
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
textView.setText(html);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question