Question

The activity works fine until the home key is pressed. Then when the app is started from the menu, the activity doesn't respond to the button press for the button listed below. When the orientation is changed then the activity starts working again.

Is this fixed by implementing(overriding) an on** method?? (ie. onResume() or onStart())

Here are my onStop and onDestroy

  @Override
    protected void onStop()
    {
        if(broadRecvr!=null)    {try{unregisterReceiver(broadRecvr);} catch(RuntimeException re) {re.getStackTrace();}}
        super.onStop(); 
    }
    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        if(wifiToggled)
        {wifi.setWifiEnabled(!wifiToggled);}
    }

these are the logcat errors; the whole logcat output is way too long to paste:

 E/ActivityManager(99): fail to set top app changed!
 E/KINETO(183): KLOG0C3- xmk_QueryOSQueue SDL Queue empty : WAIT_FOREVER 
 E/KINETO(183): KLOG0A3- ibs_os_GetMsg: Timeout forever for UKCC qHnd 0x814396ac
 E/KINETO(183): KLOG0C3- xmk_QueryOSQueue SDL Queue empty : WAIT_FOREVER 
 E/KINETO(183): KLOG0A3- ibs_os_GetMsg: Timeout forever for UKCC qHnd 0x814396ac
 E/KINETO(183): KLOG0C3- xmk_QueryOSQueue SDL Queue empty : WAIT_FOREVER 
 E/KINETO(183): KLOG0A3- ibs_os_GetMsg: Timeout forever for UKCC qHnd 0x814396ac

I am wondering how to fix a button that is not responding. This is the button code that is not working after pressing the home key:

public void setupButtons()
    {
        buttonScan = (Button) findViewById(R.id.bScan);
        buttonScan.setOnClickListener(new View.OnClickListener() {  
            public void onClick(View v) {    wifi.startScan();  }   });
    }

I am calling setupButtons() in the onCreate method.

Also, I have noticed that the buttonScan doesn't respond when I go to turn on the GPS via system menu and then return.

Was it helpful?

Solution

Solved. As I surmised, this is solved in my case by implementing the onResume method. Since onCreate is not called after an activity is resumed. Resume happens after user hitting the home button and going back to the activity. Since nothing has changed the it is not redrawn (happens @ onCreate) until the orientation is changed. Makes perfect sense to me why this is the right answer.

@Override
public void onResume() {
    super.onResume();
    //code goes here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top