Could not find method stopService(View) in a parent or ancestor Context for android:onClick attribut

我的错误场景,仅供参考:
如果是在xml里绑定的点击事件

android:onClick="startService"

哪在activity的代码里
startService()方法一定要是puulic的并且方法有View 参数

   //启动服务
    public void startService(View view) {
        startService(new Intent(this, MyService.class));
    }

Guess you like

Origin blog.csdn.net/weixin_38107457/article/details/121708010