Need Help in Fixing Force Close Issue in Android?
Hai Friends, I have created an sample application, in which i have a list view, when the user clicks the listview the next intent is called with no problem in sometimes, but most of the times it display Force Close or Wait Message as shown in the Image attached here, i want to stop displaying this Force Close or Wait Dialog, I have no idea how to stop this warning message, so guide m开发者_如何学Goe, to stop this. Pls refer my output ![alt text][1] Pls refer my Logcat Message
10-28 16:30:54.640: DEBUG/NetworkLocationProvider(76): getLocation(): triggering a wifi scan
10-28 16:30:55.410: DEBUG/NetworkLocationProvider(76): updateWifIScanResults(): 5 APs
10-28 16:30:55.430: DEBUG/LocationMasfClient(76): getNetworkLocation(): Returning cache location with accuracy 75.0
10-28 16:31:05.220: DEBUG/dalvikvm(15032): GC freed 15 objects / 600 bytes in 124ms
10-28 16:31:05.690: INFO/ActivityManager(76): Stopping service: com.google.android.apps.maps/com.google.googlenav.friend.android.LocationFriendService
10-28 16:31:09.960: DEBUG/WifiService(76): ACTION_BATTERY_CHANGED pluggedType: 2
10-28 16:31:13.186: DEBUG/KeyguardViewMediator(76): wakeWhenReadyLocked(82)
10-28 16:31:13.190: DEBUG/KeyguardViewMediator(76): handleWakeWhenReady(82)
10-28 16:31:13.190: DEBUG/KeyguardViewMediator(76): pokeWakelock(5000)
10-28 16:31:13.250: DEBUG/WifiService(76): ACTION_SCREEN_ON
10-28 16:31:13.430: DEBUG/SurfaceFlinger(76): Screen about to return, flinger = 0x1896a0
10-28 16:31:15.610: DEBUG/KeyguardViewMediator(76): pokeWakelock(5000)
This message is shown when you block the GUI thread (your only thread if you didn't created others by hand) for a long time. If you have some code in your activity that does a lot of work or sleeps for a long time, you should move this code to another thread.
I would suggest measuring the time taken by all your activity methods.
If you figure out where you are doing the heavy work you can split it out into another thread and then call back to the UI thread when your finished so you can then fire your Intent.
public class ExampleActivity extends Activity
private ProgressDialog mDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDialog= ProgressDialog.show(ExampleActivity.this, "Please wait...", "...", true);
new Thread(new Runnable() {
@Override
public void run() {
// Do some long loading
// and then
mHandler.sendEmptyMessage(1); //Notice the 1 in the switch statement
}
}).start();
}
public Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
mDialog.dismiss();
// Your back in the UI thread
// Fire whatever method you want
break;
default:
Log.i(TAG, "Handler on got message that wasnt dealt with");
break;
}
}
};
}
On a side not I can see your doing an iPhone conversion, remove the back button ... not needed nor pleasant on a UI
I hope you understand what blocking the GUI thread meant. You can try doing heavy and time taking operations like network activity inside a handler too, if you want.
精彩评论