这是我的细分:我有一个名为UserLocation的类,我在其中执行所有Location事件。在这个类中,我有一个函数public Location getLocation(Context context)
,我在其中检查位置提供程序,从所有可用提供程序获取位置,并返回最准确的。现在我想在我的SplashScreen活动中的AsyncTask
内使用此功能。我一直在阅读几个资源,我需要在Looper.prepare()
方法的开头调用doInBackground
,并在方法结束时调用Looper.loop()
。但是,我无法让它正常工作。我已经扫描了我的logcat,而且我的线路是Looper.loop()行:137
启动活动:(稍微修改以避免垃圾)
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_layout);
new LoadData().execute();
}
class LoadData extends AsyncTask <Void, Integer, Void> {
private final int prgTitle[] = { R.string.Checking_Service,
R.string.fetching_location,
R.string.Location_got,
R.string.Connect_Database};
private final int prgNums[] = {0, 10, 25, 50, 85,};
private int index;
@Override
public void onPreExecute() {
int max = 0;
for (final int p : prgNums){
max += p;
}
pBar.setMax(max);
index = 0;
}
@Override
protected Void doInBackground(Void...params) {
if(usrLoc.canGetLocation = true){
usrLoc.getLocation(mContext);
}
if(usrLoc.latitude != Double.NaN){
//do stuff
}
return null;
}
protected void onProgressUpdate(Void... loadingValues) {
pBarText.setText(prgTitle[index]);
pBar.incrementProgressBy(prgNums[index]);
++index;
publishProgress();
}
protected void onPostExecute(){
usrLoc.stopUsingGPS();
}
}
编辑:LogCat已发布
12-10 14:26:00.434: D/AndroidRuntime(894): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
12-10 14:26:00.434: D/AndroidRuntime(894): CheckJNI is ON
12-10 14:26:01.272: D/AndroidRuntime(894): Calling main entry com.android.commands.pm.Pm
12-10 14:26:01.312: D/AndroidRuntime(894): Shutting down VM
12-10 14:26:01.332: I/AndroidRuntime(894): NOTE: attach of thread 'Binder Thread #3' failed
12-10 14:26:01.342: D/dalvikvm(894): GC_CONCURRENT freed 101K, 78% free 462K/2048K, paused 1ms+2ms
12-10 14:26:01.342: D/dalvikvm(894): Debugger has detached; object registry had 1 entries
12-10 14:26:01.932: D/AndroidRuntime(907): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
12-10 14:26:01.932: D/AndroidRuntime(907): CheckJNI is ON
12-10 14:26:02.864: D/AndroidRuntime(907): Calling main entry com.android.commands.am.Am
12-10 14:26:02.892: I/ActivityManager(91): Force stopping package com.book.swap uid=10040
12-10 14:26:02.892: W/ActivityManager(91): Force removing ActivityRecord{41785ec8 com.book.swap/.SplashScreen}: app died, no saved state
12-10 14:26:02.892: I/Process(91): Sending signal. PID: 877 SIG: 9
12-10 14:26:02.922: W/NetworkManagementSocketTagger(91): setKernelCountSet(10040, 0) failed with errno -2
12-10 14:26:02.992: W/NetworkManagementSocketTagger(91): setKernelCountSet(10005, 1) failed with errno -2
12-10 14:26:03.022: I/ActivityManager(91): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.book.swap/.SplashScreen} from pid 907
12-10 14:26:03.073: I/WindowManager(91): createSurface Window{41af7978 com.android.launcher/com.android.launcher2.Launcher paused=false}: DRAW NOW PENDING
12-10 14:26:03.092: W/WindowManager(91): Failure taking screenshot for (240x394) to layer 21005
12-10 14:26:03.102: D/AndroidRuntime(907): Shutting down VM
12-10 14:26:03.152: I/AndroidRuntime(907): NOTE: attach of thread 'Binder Thread #3' failed
12-10 14:26:03.163: D/dalvikvm(907): GC_CONCURRENT freed 101K, 77% free 485K/2048K, paused 1ms+1ms
12-10 14:26:03.163: D/jdwp(907): Got wake-up signal, bailing out of select
12-10 14:26:03.163: D/dalvikvm(907): Debugger has detached; object registry had 1 entries
12-10 14:26:03.191: D/dalvikvm(918): Not late-enabling CheckJNI (already on)
12-10 14:26:03.202: I/WindowManager(91): createSurface Window{41a24bd0 Starting com.book.swap paused=false}: DRAW NOW PENDING
12-10 14:26:03.222: I/ActivityManager(91): Start proc com.book.swap for activity com.book.swap/.SplashScreen: pid=918 uid=10040 gids={3003}
12-10 14:26:03.522: W/NetworkManagementSocketTagger(91): setKernelCountSet(10040, 1) failed with errno -2
12-10 14:26:03.662: W/ActivityThread(918): Application com.book.swap is waiting for the debugger on port 8100...
12-10 14:26:03.672: I/System.out(918): Sending WAIT chunk
12-10 14:26:03.682: I/dalvikvm(918): Debugger is active
12-10 14:26:03.872: I/System.out(918): Debugger has connected
12-10 14:26:03.872: I/System.out(918): waiting for debugger to settle...
12-10 14:26:04.072: I/System.out(918): waiting for debugger to settle...
12-10 14:26:04.202: I/WindowManager(91): createSurface Window{41adaa20 Waiting For Debugger paused=false}: DRAW NOW PENDING
12-10 14:26:04.272: I/System.out(918): waiting for debugger to settle...
12-10 14:26:04.498: I/System.out(918): waiting for debugger to settle...
12-10 14:26:04.692: I/System.out(918): waiting for debugger to settle...
12-10 14:26:04.904: I/System.out(918): waiting for debugger to settle...
12-10 14:26:05.102: I/System.out(918): waiting for debugger to settle...
12-10 14:26:05.122: W/InputManagerService(91): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@417c64e8
12-10 14:26:05.355: I/System.out(918): waiting for debugger to settle...
12-10 14:26:05.619: I/System.out(918): waiting for debugger to settle...
12-10 14:26:05.822: I/System.out(918): waiting for debugger to settle...
12-10 14:26:06.065: I/System.out(918): waiting for debugger to settle...
12-10 14:26:06.287: I/System.out(918): waiting for debugger to settle...
12-10 14:26:06.513: I/System.out(918): debugger has settled (1427)
12-10 14:26:13.132: W/ActivityManager(91): Launch timeout has expired, giving up wake lock!
12-10 14:26:13.597: W/ActivityManager(91): Activity idle timeout for ActivityRecord{418af8c8 com.book.swap/.SplashScreen}
12-10 14:31:31.391: A/NetworkStats(91): problem reading network stats
12-10 14:31:31.391: A/NetworkStats(91): java.lang.IllegalStateException: problem parsing line: null
12-10 14:31:31.391: A/NetworkStats(91): at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:313)
12-10 14:31:31.391: A/NetworkStats(91): at com.android.server.NetworkManagementService.getNetworkStatsUidDetail(NetworkManagementService.java:1271)
12-10 14:31:31.391: A/NetworkStats(91): at com.android.server.net.NetworkStatsService.performPollLocked(NetworkStatsService.java:810)
12-10 14:31:31.391: A/NetworkStats(91): at com.android.server.net.NetworkStatsService.performPoll(NetworkStatsService.java:771)
12-10 14:31:31.391: A/NetworkStats(91): at com.android.server.net.NetworkStatsService.access$100(NetworkStatsService.java:128)
12-10 14:31:31.391: A/NetworkStats(91): at com.android.server.net.NetworkStatsService$3.onReceive(NetworkStatsService.java:610)
12-10 14:31:31.391: A/NetworkStats(91): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
12-10 14:31:31.391: A/NetworkStats(91): at android.os.Handler.handleCallback(Handler.java:605)
12-10 14:31:31.391: A/NetworkStats(91): at android.os.Handler.dispatchMessage(Handler.java:92)
12-10 14:31:31.391: A/NetworkStats(91): at android.os.Looper.loop(Looper.java:137)
12-10 14:31:31.391: A/NetworkStats(91): at android.os.HandlerThread.run(HandlerThread.java:60)
12-10 14:31:31.391: A/NetworkStats(91): Caused by: java.io.FileNotFoundException: /proc/net/xt_qtaguid/stats: open failed: ENOENT (No such file or directory)
12-10 14:31:31.391: A/NetworkStats(91): at libcore.io.IoBridge.open(IoBridge.java:406)
12-10 14:31:31.391: A/NetworkStats(91): at java.io.FileInputStream.<init>(FileInputStream.java:78)
12-10 14:31:31.391: A/NetworkStats(91): at java.io.FileReader.<init>(FileReader.java:42)
12-10 14:31:31.391: A/NetworkStats(91): at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:272)
12-10 14:31:31.391: A/NetworkStats(91): ... 10 more
12-10 14:31:31.391: A/NetworkStats(91): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
12-10 14:31:31.391: A/NetworkStats(91): at libcore.io.Posix.open(Native Method)
12-10 14:31:31.391: A/NetworkStats(91): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:98)
12-10 14:31:31.391: A/NetworkStats(91): at libcore.io.IoBridge.open(IoBridge.java:390)
12-10 14:31:31.391: A/NetworkStats(91): ... 13 more