How to pass a value in Services?

前端 未结 2 1018
清酒与你
清酒与你 2021-01-16 19:55

I am making a media player ,who can run in background. i have to send a string uri in this service. but i cant send the uri value from my activity through bundle.Services cl

2条回答
  •  太阳男子
    2021-01-16 20:07

    If you are trying to send a string or String-array from one Activity to another this can be done in the Intent.

    In ClassA:

    Intent intent = new Intent(this, ClassB);
    tring[] myStrings = new String[] {"test", "test2"};
    intent.putExtra("strings", myStrings);
    startActivity(intent);

    In ClassB:

    public void onCreate() {
    Intent intent = getIntent();
    String[] myStrings = intent.getStringArrayExtra("strings");
    }

提交回复
热议问题