Error with resultCode in onActivityForResult after calling startActivityForResult

别说谁变了你拦得住时间么 提交于 2019-12-13 00:22:45

问题


I am enabling Bluetooth services through an Intent and calling startActivityForResult() method as follows:

public void enableBT(BluetoothAdapter adapter) {
        if (!adapter.isEnabled()) {
            Intent enableBTIntent = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            startActivityForResult(enableBTIntent, ENABLE_BT_INTENT);
        }
    }

In this code, adapter is BluetoothAdapter object. After this I call onActivityResult() as follows:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == ENABLE_BT_INTENT)
            if(resultCode == Activity.RESULT_OK)
                 button.setText("Done");

But after I enable the Bluetooth, the button.setText("Done"); piece of code is not executed.

Where is the problem ?

Thanks.


回答1:


button.setText(resultCode); gives an error because resultCode is an int so its looking for a resource with that id. See the two methods of setText(). You can use

button.setText(String.valueOf(resultCode));

If you want the String value of that int to be displayed. Otherwise please explain better what you want to happen.



来源:https://stackoverflow.com/questions/18278820/error-with-resultcode-in-onactivityforresult-after-calling-startactivityforresul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!