Original code:
Private handler mhandler = new handler (){
@ Override
Public void handlemessage (Message MSG ){
Switch (msg. What ){
Case get_current_time:
Intent actiongetduration = new intent ("x1.getduration ");
Sendbroadcast (actiongetduration );
Msumtv. settext (helper. sumduration );
Mnowtv. settext (helper. currentduration );
If (helper. currentsecond = helper. sumsecond) // The playback is complete.
{
If (helper. currentsecond = 0)
{
Log. D (TAG, "In currentsecond = 0 ");
}
}
Else
{
Log. D (TAG, "In set progress ");
Log. D (TAG, "helper. sumsecond =" + helper. sumsecond );
Long position = mseekbar. getmax () * helper. currentsecond/helper. sumsecond;
Mseekbar. setprogress (INT) position );
}
Break;
}
}
};
Modified code:
Static class myhandler extends handler {
Weakreference <browseractivity> mactivity;
Myhandler (browseractivity activity ){
Mactivity = new weakreference <browseractivity> (activity );
}
@ Override
Public void handlemessage (Message MSG ){
Browseractivity theactivity = mactivity. Get ();
Switch (msg. What ){
Case get_current_time:
Intent actiongetduration = new intent ("x1.getduration ");
Theactivity. sendbroadcast (actiongetduration );
Theactivity. msumtv. settext (helper. sumduration );
Theactivity. mnowtv. settext (helper. currentduration );
If (helper. currentsecond = helper. sumsecond) // The playback is complete.
{
If (helper. currentsecond = 0)
{
Log. D (TAG, "In currentsecond = 0 ");
}
}
Else
{
Log. D (TAG, "In set progress ");
Log. D (TAG, "helper. sumsecond =" + helper. sumsecond );
Long position = theactivity. mseekbar. getmax () * helper. currentsecond/helper. sumsecond;
Theactivity. mseekbar. setprogress (INT) position );
}
Break;
}
}
};
Private myhandler mhandler = new myhandler (this );
The warning in the location where the mhandler is defined disappears, but the error fatal signal 6 (SIGABRT) at 0x00000138 (code = 0) still occurs, it is reported in libc, and the program crashes. the ANR error is displayed, and the reason is: keydispatchingtimedout. Continue to solve the bug. I really don't know where the problem is.