当我想发送"拍照意图"时,问题就开始了。 在htc one +(我测试我的应用程序的手机上),似乎这个意图对于我的应用程序来说太重了,它调用onTrimMemory方法(当你的应用消耗太多内存并且即将停止时显然会调用该方法)然后应用程序停止。 所以我决定在处理Intent的AsyncTask上调用cancel()方法。但接下来该怎么办? 以下是相关摘录:
private class djford extends AsyncTask<Void,Void,Void>{
@Override
protected Void doInBackground(Void... voids) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, TAKE_PHOTO_CODE);
while(1>0){
if(isCancelled()){
***// WHAT SHOULD I DO HERE??***
}
}
}
return null;
}
}
@Override
public void onTrimMemory(int level) {
if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) {
fff.cancel(false);
tv1.setText("canceled before stopping");
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode==RESULT_OK){
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK)
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ImageView.setImageBitmap(imageBitmap);
}
else {
Uri returnUri = data.getData();
imageView.setImageURI(returnUri);
}
}
else
{
return;
}
}