Skip to content Skip to sidebar Skip to footer

How To Sort Togglebutton Listener And Asynctask Call?

I will try to set the question without pasting any code because will be probably more clear. I have an android application with one ToggleButton. When the ToggleButton is 'ON' it s

Solution 1:

There can be several possible ways. You can use broadcast sender and receiver for you case.

Steps mentioned below:

Step 1: Create a broadcast receiver in your AsyncTask to receive broadcast from your activity.

BroadcastReceiverreceiver=newBroadcastReceiver() {

        @OverridepublicvoidonReceive(Context context, Intent intent) {
            if (intent.getAction().equals("close_socket")) {
                // close your socket here.
            }
        }
    };

Step 2: Register your receiver after creating your broadcast receiver.

IntentFilter filter=new IntentFilter("close_socket");
registerReceiver(receiver, filter);

Step 3: Send broadcast from your activity to close socket.

Intentintent=newIntent("close_socket");
SendBroadcast(intent);

Wherever you have registered your broadcast receiver it will automatically receive broadcast and close socket. Hope it will help you.

Post a Comment for "How To Sort Togglebutton Listener And Asynctask Call?"