我有一个Android应用程序,适用于Lollipop(5.0)以下的所有操作系统版本。对于Lollipop及更高版本,但它崩溃了
AsyncTask
我不知道是什么原因引起了我的怀疑,我必须以某种方式用我的编码风格冒犯ART?
我的应用程序中根本没有本机代码,我最大的努力是将崩溃跟踪到在onCreate
中加载来自文件系统的联系人的方法(在AsyncTask
中调用)应用程序崩溃时调用的活动的数量。
AsyncTask
中使用此代码时,它会崩溃onCreate
中未使用此代码,则代码仍会崩溃。onResume
,23Kb, 65Kb and 48Kb
还是其他我也不相信它是一个内存问题,因为我只在联系人列表中加载了3个项目。每个列表的行都有大小的图像
分别为 /**
*
* Loads the contacts list
*/
public static void loadContactsList(final Runnable onComplete){
final Context context = getApplicationContext();
class Loader extends AsyncTask<String, Void, ArrayList<Client>> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}//end method onPreExecute.
@Override
protected ArrayList<Client> doInBackground(String... params) {
List<String>ids = Client.loadClientIds(context);
Utils.logErrorMessage("ids = "+ids);
ArrayList<Client>main = new ArrayList<Client>();
for(String id:ids){
Client c = Client.loadClient(context,id,true);
if(c!=null && !c.isOwner()){
main.add(c);
}
}
Utils.logErrorMessage("done loading clients: see = "+main.size()+" clients loaded");
return main;
}
@Override
protected void onPostExecute(final ArrayList<Client> result) {
super.onPostExecute(result);
Utils.logErrorMessage("On ui thread, showing results! adapter = "+ContactsActivity.adapter);
ContactsActivity.adapter.setClients( result );
onComplete.run();
Utils.logErrorMessage("Done rendering in onPostExecute!");
}// end onPostExecute
}// end inner class
new Loader().execute();
/*
Handler mHandler = new Handler(Looper.getMainLooper());
mHandler.post(new Runnable() {
public void run() {
new Loader().execute();
}
});
*/
}
。
我已经使用此代码在运行KitKat和更低版本的android的设备上加载了更多的联系人。
以下是违规代码(违反ART,而不是Dalvik):
loadClient
每当在我的应用程序中的任何活动中调用此方法时,它都会崩溃。
/**
* Loads an Interact friend on this device.
* @param id the id of the Client to be loaded
* @param loadProfileImage If true, the client's profile image is loaded
* in the process. For some applications, the image does not need to be
* loaded so set it to false.
*/
public static Client loadClient(Context context,String id,boolean loadProfileImage){
File clientData = new File(Utils.CONTACTS_FOLDER.getAbsolutePath()+"/"+id+".txt");
if(!clientData.exists()){
//Perhaps its an owner account, search for that too.
clientData = new File(Utils.CONTACTS_FOLDER.getAbsolutePath()+"/_owner"+id+".txt");
if(!clientData.exists()){
return null;
}
}
String clientsJSON = new TextFileReader(clientData).read();
Client client = parseJsonToClient(clientsJSON);
if(loadProfileImage && client!=null && client.getProfilePix() != null && !client.getProfilePix().isEmpty()){
client.setData(ImageUtilities.loadIcon(client.getProfilePix()));
}
return client;
}
的代码是:
01-01 19:27:13.906: A/libc(12495): Fatal signal 11 (SIGSEGV), code 1, fault addr 0xa001cc10 in tid 12505 (FinalizerDaemon)
01-01 19:27:14.010: I/DEBUG(75): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-01 19:27:14.010: I/DEBUG(75): Build fingerprint: 'generic/vbox86tp/vbox86tp:5.0/LRX21M/buildbot12151835:userdebug/test-keys'
01-01 19:27:14.010: I/DEBUG(75): Revision: '0'
01-01 19:27:14.010: I/DEBUG(75): ABI: 'x86'
01-01 19:27:14.010: I/DEBUG(75): pid: 12495, tid: 12505, name: FinalizerDaemon >>> supernet.interactapp <<<
01-01 19:27:14.010: I/DEBUG(75): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x3
01-01 19:27:14.033: I/DEBUG(75): eax ffffffff ebx b571ebac ecx 00000001 edx ffffffff
01-01 19:27:14.033: I/DEBUG(75): esi a001cc10 edi a001cc10
01-01 19:27:14.033: I/DEBUG(75): xcs 00000073 xds 0000007b xes 0000007b xfs 0000002f xss 0000007b
01-01 19:27:14.033: I/DEBUG(75): eip b539c9fb ebp 00000000 esp b39e7970 flags 00210286
01-01 19:27:14.033: I/DEBUG(75): backtrace:
01-01 19:27:14.033: I/DEBUG(75): #00 pc 001019fb /system/lib/libskia.so (SkBitmap::freePixels()+43)
01-01 19:27:14.033: I/DEBUG(75): #01 pc 00101a6a /system/lib/libskia.so (SkBitmap::~SkBitmap()+26)
01-01 19:27:14.033: I/DEBUG(75): #02 pc 000dcee3 /system/lib/libandroid_runtime.so
01-01 19:27:14.033: I/DEBUG(75): #03 pc 0001cbfe /data/dalvik-cache/x86/system@framework@boot.oat
01-01 19:27:14.033: I/DEBUG(75): #04 pc fffffffe <unknown>
01-01 19:27:14.137: I/DEBUG(75): Tombstone written to: /data/tombstones/tombstone_02
01-01 19:27:14.138: I/BootReceiver(456): Copying /data/tombstones/tombstone_02 to DropBox (SYSTEM_TOMBSTONE)
请提供任何帮助。
修改
当我在@Tasos建议的情况下关闭清单中的硬件加速时,日志也变为:
{{1}}