我的AsyncTask
中有一堆对我的数据库(ParseContent.queryGMG(...))的调用,我需要它们都在那里,否则应用程序加载速度很慢。导致应用程序崩溃的唯一原因是因为它在其他方法中需要,所以我已经先实例化变量appAbbrev
,然后我尝试在AsyncTask
内部类中实例化它。显然这不起作用,我的应用程序崩溃。我该怎么办?
工作但速度太慢,因为它在onCreate()
方法中:
public class ... {
SparseArray<String> itemAction = null;
public void onCreate(Bundle savedInstanceState) {
try {
itemAction = ParseContent.queryGMG("action");
} catch (ParseException e) {
e.printStackTrace();
}
}
无效,因为我将其移至AsyncTask
内部类:
public class ... {
SparseArray<String> itemAction = null;
public void onCreate(Bundle savedInstanceState) {
...
}
private class Load extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... params) {
try {
itemAction = ParseContent.queryGMG("action");
} catch (ParseException e) {
e.printStackTrace();
}
}
}
这是LogCat(不确定相关内容以及如何设置样式):
01-17 17:43:31.342: E/WindowManager(32404): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
01-17 17:43:31.342: E/WindowManager(32404): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3576)
01-17 17:43:31.342: E/WindowManager(32404): at android.app.ActivityThread.access$800(ActivityThread.java:143)
01-17 17:43:31.342: E/WindowManager(32404): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
01-17 17:43:31.342: E/WindowManager(32404): at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 17:43:31.342: E/WindowManager(32404): at android.os.Looper.loop(Looper.java:137)
01-17 17:43:31.342: E/WindowManager(32404): at android.app.ActivityThread.main(ActivityThread.java:4950)
01-17 17:43:31.342: E/WindowManager(32404): at java.lang.reflect.Method.invokeNative(Native Method)
01-17 17:43:31.342: E/WindowManager(32404): at java.lang.reflect.Method.invoke(Method.java:511)
01-17 17:43:31.342: E/WindowManager(32404): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
01-17 17:43:31.342: E/WindowManager(32404): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
01-17 17:43:31.342: E/WindowManager(32404): at dalvik.system.NativeStart.main(Native Method)
01-17 17:43:31.362: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.362: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.362: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.512: E/Sensors(729): accelHandler -0.235909 6.980284 6.538404
01-17 17:43:31.532: E/KeyguardViewMediator(729): 3. Lockscreen unlock
01-17 17:43:31.532: E/KeyguardViewMediator(729): Phone is boot completed. so can broadcast
01-17 17:43:31.532: E/KeyguardViewMediator(729): Phone is boot completed. so can broadcast
01-17 17:43:31.532: E/MotionRecognitionService(729): mReceiver.onReceive : ACTION_USER_PRESENT :: UNLOCK SCREEN
01-17 17:43:31.552: E/MP-Decision(1919): mpdecision_server(): New Decision parameters Nw=1.990000, Tw=140, Ns=1.100000, Ts=190, DI=50, poll=9, util_h=70, util_l=60
01-17 17:43:31.693: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.703: E/AudioPolicyManagerBase(207): unknown stream type
01-17 17:43:31.703: E/AudioPolicyManagerBase(207): unknown stream type
01-17 17:43:31.703: E/AudioPolicyManagerBase(207): unknown stream type
01-17 17:43:31.703: E/AudioPolicyManagerBase(207): unknown stream type
01-17 17:43:31.703: E/AudioPolicyManagerBase(207): unknown stream type
01-17 17:43:31.703: E/AudioPolicyManagerBase(207): unknown stream type
01-17 17:43:31.773: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.793: E/MP-Decision(1919): mpdecision_server(): New Decision parameters Nw=2.400000, Tw=150, Ns=1.400000, Ts=100, DI=50, poll=9, util_h=100, util_l=0
01-17 17:43:31.873: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.873: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.873: E/WindowManager(729): updateResizingWindows:: winAnimator.mSurfaceResized = true
01-17 17:43:31.883: E/SMD(200): DCD ON
01-17 17:43:31.973: E/MTPRx(1228): In MtpReceiverandroid.intent.action.USER_PRESENT
01-17 17:43:31.973: E/MTPRx(1228): check value of boot_completed is1
01-17 17:43:31.973: E/MTPRx(1228): check booting is completed_sys.boot_completed
01-17 17:43:31.973: E/MTPRx(1228): Sd-Card path/storage/extSdCard
01-17 17:43:31.973: E/MTPRx(1228): Status for mount/Unmount :removed
01-17 17:43:31.973: E/MTPRx(1228): SDcard is not available
01-17 17:43:31.973: E/MTPRx(1228): The value of first_boot is 1
01-17 17:43:31.973: E/MTPRx(1228): [ 662] The value of first_boot is 1NORMAL SEQUENCE
01-17 17:43:32.453: E/PowerManagerService(729): WakeLock : binderDied()
01-17 17:43:32.463: E/InputDispatcher(729): channel ~ Channel is unrecoverably broken and will be disposed!
01-17 17:43:32.473: E/MP-Decision(1919): mpdecision_server(): New Decision parameters Nw=1.990000, Tw=140, Ns=1.100000, Ts=190, DI=50, poll=9, util_h=70, util_l=60
01-17 17:43:32.944: E/ClockAlarmWidget(3842): [AlarmWidgetIdManager] getListItem() : itemIndex=0, widgetID:1
01-17 17:43:32.944: E/ClockAlarmWidget(3842): [AlarmWidgetIdManager] getListItem() : ItemIndex exceed ListItemCount. itemIndex=1
01-17 17:43:32.944: E/ClockAlarmWidget(3842): [AlarmWidgetIdManager] getListItem() : itemIndex=1, widgetID:1
01-17 17:43:34.125: E/AlarmWidget(3767): [AlarmWidgetService] getViewAt position = 0 mPosition = 3
01-17 17:43:34.125: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : itemIndex=1, widgetID:12
01-17 17:43:34.145: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : itemIndex=1, widgetID:12
01-17 17:43:34.155: E/AlarmWidget(3767): [AlarmWidgetService] getViewAt position = 1 mPosition = 0
01-17 17:43:34.155: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : ItemIndex exceed ListItemCount. itemIndex=2
01-17 17:43:34.155: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : itemIndex=2, widgetID:12
01-17 17:43:34.155: E/AlarmWidget(3767): [AlarmWidgetService] getViewAt position = 2 mPosition = 1
01-17 17:43:34.155: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : ItemIndex exceed ListItemCount. itemIndex=3
01-17 17:43:34.155: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : itemIndex=3, widgetID:12
01-17 17:43:34.155: E/AlarmWidget(3767): [AlarmWidgetService] getViewAt position = 3 mPosition = 2
01-17 17:43:34.165: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : ItemIndex exceed ListItemCount. itemIndex=4
01-17 17:43:34.165: E/AlarmWidget(3767): [AlarmWidgetIdManager] getListItem() : itemIndex=4, widgetID:12
01-17 17:43:34.265: E/ALSAModule(207): s_standby handle h 0x41df9ed8
01-17 17:43:34.486: E/ALSAModule(207): Number of modifiers 0
01-17 17:43:34.486: E/ALSAModule(207): usecase_type is 0
01-17 17:43:34.756: E/MP-Decision(1919): DOWN Ld:24 Ns:1.100000 Ts:190 rq:0.100000 seq:196.000000
01-17 17:43:34.886: E/SMD(200): DCD ON
01-17 17:43:35.647: E/MP-Decision(1919): CPU[1] has been hotplugged outside MP-Decision.
01-17 17:43:35.647: E/MP-Decision(1919): MP-Decision will be stalled until enabled.
01-17 17:43:36.648: E/MP-Decision(1919): Enabling MP decision for CPU[1]
01-17 17:43:37.889: E/SMD(200): DCD ON
01-17 17:43:38.780: E/MP-Decision(1919): CPU[1] has been hotplugged outside MP-Decision.
01-17 17:43:38.780: E/MP-Decision(1919): MP-Decision will be stalled until enabled.
01-17 17:43:39.771: E/MP-Decision(1919): Enabling MP decision for CPU[1]
01-17 17:43:39.771: E/MP-Decision(1919): DOWN Ld:6 Ns:1.100000 Ts:190 rq:0.000000 seq:999.000000
01-17 17:43:40.882: E/SMD(200): DCD ON
01-17 17:43:41.002: E/MP-Decision(1919): CPU[1] has been hotplugged outside MP-Decision.
01-17 17:43:41.002: E/MP-Decision(1919): MP-Decision will be stalled until enabled.
01-17 17:43:41.513: E/Sensors(729): accelHandler -0.223934 6.577921 6.988667
01-17 17:43:42.014: E/MP-Decision(1919): Enabling MP decision for CPU[1]
01-17 17:43:43.385: E/MP-Decision(1919): CPU[1] has been hotplugged outside MP-Decision.
01-17 17:43:43.385: E/MP-Decision(1919): MP-Decision will be stalled until enabled.
01-17 17:43:43.485: E/Mms/MessageUtils(31975): updateCountryIso : update country iso info
01-17 17:43:43.535: E/Mms/MessageUtils(31975): updateCountryIso : update country iso info
01-17 17:43:43.555: E/IPPhoneSettings(31975): getString(CELL_ONLY) = 0
01-17 17:43:43.795: E/TwAdapterView(31975): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState12
01-17 17:43:43.795: E/TwAdapterView(31975): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState12
01-17 17:43:43.886: E/SMD(200): DCD ON
01-17 17:43:43.976: E/hwcomposer(204): void qhwc::QueuedBufferStore::unlockBuffer(private_handle_t*) Invalid Handle
01-17 17:43:44.206: E/TwAdapterView(31975): TwAdapterView AdapterDataSetObserver onChanged ItemCount before onRestoreInstanceState64
01-17 17:43:44.206: E/TwAdapterView(31975): TwAdapterView AdapterDataSetObserver onChanged ItemCount after onRestoreInstanceState64
01-17 17:43:44.276: E/overlay(204): Failed to call ioctl MSMFB_OVERLAY_SET err=Operation not permitted
01-17 17:43:44.276: E/overlay(204): MdpCtrl failed to setOverlay, restoring last known good ov info
答案 0 :(得分:0)
试试这个:
public class MyClass {
private SparseArray<String> itemAction;
public void onCreate(Bundle savedInstanceState) {
...
}
private class Load extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... params) {
try {
MyClass.this.itemAction = ParseContent.queryGMG("action");
} catch (ParseException e) {
e.printStackTrace();
}
}
}