我正在使用AsyncTask
将图像转换为base64
值。该任务在后台运行,应用程序移动到下一个活动。如何检查AsyncTask
的状态以检查它是否已完成...
我的异步任务代码...
public class Asyncimg extends AsyncTask<Void, Integer, String>
{
//for converting images to base64
protected void onPreExecute (){
//disbaling sync button on converting pic to base64
}
protected String doInBackground(Void...arg0) {
Cursor cursor = mydb.getDat1();
//fetching the image location
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
for( int i=0 ; i< 1 ; i++ )
{
if( cursor.getColumnName(i) != null )
{
try
{
if( cursor.getString(i) != null )
{
//saving image to bitmap
Bitmap bitmap = BitmapFactory.decodeFile(cursor.getString(cursor.getColumnIndex(DBHelper.PHOTO)));
//converting it to base64
String en= encodeToBase64( resize(bitmap,1080,1920), Bitmap.CompressFormat.JPEG,50);
Log.d("base",en);
//inserting it to table pic
mydb.insertpic(cursor.getInt(1),en);
}
}
catch( Exception ignored)
{
}
}
}
cursor.moveToNext();
}
cursor.close();
mydb.updatebin();
return null;
}
protected void onPostExecute(String result) {
}
}
我该如何从另一个活动中检查它的状态?