Send whole of a class to a Mainactivity

0

Good afternoon to the community. I need your help to solve a novice problem like me, but that has me stuck.

In general, what I want is to send an entire data from a second class extended in BroacastReceiver to the main class Mainactivity.

The program I am using is the following program

Sorry for my frankness. I really do not ask you to solve the problem without doing anything but if they could be a bit simple in your expression I would appreciate it. I'm a novice in this programming, but this stage is only part of the project.

Waiting for an answer I thank you for your time.

    
asked by Miguel_JGL 28.09.2017 в 22:13
source

1 answer

0

If we edit the answer to the question Help with getter on android you did. We would only have to implement the method onReceive in onCreate and then activate / deactivate the button according to the state:

//..
private MusicIntentReceiver myReceiver;

@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Button button = (Buttton)findViewById(R.id.id_boton);

    myReceiver = new MusicIntentReceiver(){

        @Override
        public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
            int state = intent.getIntExtra("state", -1);
            switch (state) {
            case 0:
            // desactivamos el buton
               button.setEnabled(false);
                break;
            case 1:
            // activamos
               button.setEnabled(true);
                break;
            default:
                Log.d(TAG, "I have no idea what the headset state is");
            }
        }
   };
}

@Override public void onResume() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    registerReceiver(myReceiver, filter);
    super.onResume();
}
    
answered by 28.09.2017 в 22:55