如何在后台执行Android任务
我正在制作一个Android应用程序,它从文件(即手机SD卡)中获取数据,并根据时间,以html格式(即web浏览器)显示数据。该应用程序连续运行。我有两个任务,第一次计算并从文件中获取数据是连续的,第二次在web浏览器上显示数据也是连续的。我想在后台运行第一个任务,并在html中连续显示其他任务 我不知道该怎么做..而且我是android新手..请帮帮我.谢谢..你要找的。AysncTask有doInBackground()方法来执行耗时的任务。所有其他方法都在主线程上运行。类似这样的东西如何在后台执行Android任务,android,Android,我正在制作一个Android应用程序,它从文件(即手机SD卡)中获取数据,并根据时间,以html格式(即web浏览器)显示数据。该应用程序连续运行。我有两个任务,第一次计算并从文件中获取数据是连续的,第二次在web浏览器上显示数据也是连续的。我想在后台运行第一个任务,并在html中连续显示其他任务 我不知道该怎么做..而且我是android新手..请帮帮我.谢谢..你要找的。AysncTask有doInBackground()方法来执行耗时的任务。所有其他方法都在主线程上运行。类似这样的东西 n
new AsyncTask<Void, String, String>() {
@Override
protected void onPreExecute() {
// before executing background task. Like showing a progress dialog
}
@Override
protected String doInBackground(Void... params) {
// Do background task here
}
@Override
protected void onPostExecute(String msg) {
// This will be executed when doInBackground() is finished.
// "msg" is value returned by doInBackground()
}
}.execute(null, null, null);
newasynctask(){
@凌驾
受保护的void onPreExecute(){
//在执行后台任务之前。例如显示进度对话框
}
@凌驾
受保护字符串doInBackground(无效…参数){
//在这里做背景任务
}
@凌驾
受保护的void onPostExecute(字符串msg){
//这将在doInBackground()完成时执行。
//“msg”是doInBackground()返回的值
}
}.执行(空,空,空);
您正在寻找的。AysncTask有doInBackground()方法来执行耗时的任务。所有其他方法都在主线程上运行。类似这样的东西new AsyncTask<Void, String, String>() {
@Override
protected void onPreExecute() {
// before executing background task. Like showing a progress dialog
}
@Override
protected String doInBackground(Void... params) {
// Do background task here
}
@Override
protected void onPostExecute(String msg) {
// This will be executed when doInBackground() is finished.
// "msg" is value returned by doInBackground()
}
}.execute(null, null, null);
newasynctask(){
@凌驾
受保护的void onPreExecute(){
//在执行后台任务之前。例如显示进度对话框
}
@凌驾
受保护字符串doInBackground(无效…参数){
//在这里做背景任务
}
@凌驾
受保护的void onPostExecute(字符串msg){
//这将在doInBackground()完成时执行。
//“msg”是doInBackground()返回的值
}
}.执行(空,空,空);
您正在寻找的。AysncTask有doInBackground()方法来执行耗时的任务。所有其他方法都在主线程上运行。类似这样的东西new AsyncTask<Void, String, String>() {
@Override
protected void onPreExecute() {
// before executing background task. Like showing a progress dialog
}
@Override
protected String doInBackground(Void... params) {
// Do background task here
}
@Override
protected void onPostExecute(String msg) {
// This will be executed when doInBackground() is finished.
// "msg" is value returned by doInBackground()
}
}.execute(null, null, null);
newasynctask(){
@凌驾
受保护的void onPreExecute(){
//在执行后台任务之前。例如显示进度对话框
}
@凌驾
受保护字符串doInBackground(无效…参数){
//在这里做背景任务
}
@凌驾
受保护的void onPostExecute(字符串msg){
//这将在doInBackground()完成时执行。
//“msg”是doInBackground()返回的值
}
}.执行(空,空,空);
您正在寻找的。AysncTask有doInBackground()方法来执行耗时的任务。所有其他方法都在主线程上运行。类似这样的东西new AsyncTask<Void, String, String>() {
@Override
protected void onPreExecute() {
// before executing background task. Like showing a progress dialog
}
@Override
protected String doInBackground(Void... params) {
// Do background task here
}
@Override
protected void onPostExecute(String msg) {
// This will be executed when doInBackground() is finished.
// "msg" is value returned by doInBackground()
}
}.execute(null, null, null);
newasynctask(){
@凌驾
受保护的void onPreExecute(){
//在执行后台任务之前。例如显示进度对话框
}
@凌驾
受保护字符串doInBackground(无效…参数){
//在这里做背景任务
}
@凌驾
受保护的void onPostExecute(字符串msg){
//这将在doInBackground()完成时执行。
//“msg”是doInBackground()返回的值
}
}.执行(空,空,空);
如果您想获得高级,您可能正在寻找AsyncTask
或AsyncTaskLoader
,或者甚至可能是RxJava
,但如果这是一项持久的操作,您也应该查找IntentService
。您可能正在寻找AsyncTask
或AsyncTaskLoader
,甚至可能是RxJava
如果你想获得高级,但是如果你想获得高级,你还应该查找IntentService
如果它是一项持久的操作。你可以查找AsyncTask
或者AsyncTaskLoader
或者甚至RxJava
,如果你想获得高级,你还应该查找IntentService
这就是一个操作的持久性。你要么在寻找AsyncTask
或者AsyncTaskLoader
,或者如果你想获得高级,甚至可能是RxJava
,但是如果这是一个持久性很强的操作,你也应该查找IntentService
。这个方法在android 11中是不完善的。试试这个方法吧android 11中的去润滑尝试此方法在android 11中的去润滑尝试此方法在android 11中的去润滑尝试此方法