我正在尝试在Android Wear中通过一个表盘启动一项活动,方法是:
Intent myIntent = new Intent(this, com.jorc.android.wearable.watchface.watchface.MainActivity.class);
getApplicationContext().startActivity(myIntent);然而,我得到了这个错误。
Error:(564, 39) error: no suitable constructor found for Intent(DigitalWatchFaceService.Engine,Class<MainActivity>)
constructor Intent.Intent(String,Uri) is not applicable
(argument mismatch; DigitalWatchFaceService.Engine cannot be converted to String)
constructor Intent.Intent(Context,Class<?>) is not applicable
(argument mismatch; DigitalWatchFaceService.Engine cannot be converted to Context)我的问题是:“有没有办法从表盘开始一项活动?”Watchface使用扩展CanvasWatchFaceService的CanvasWatchFaceService.Engine。
发布于 2017-12-24 20:35:20
在使用Intent myIntent = new Intent(this,...MainActivity.class) MainActivity.class时,有一个小的缺失部分) intent是在另一个类中创建的,此处是一个匿名内部类画布,单击listener。代码并没有像预期的那样引用活动(或上下文)的实例,而是匿名内部类canvas ClickListener的实例。
因此,正确的方法是提供正确的类上下文。
Intent myIntent = new Intent(DigitalWatchFaceService.this, com.jorc.android.wearable.watchface.watchface.MainActivity.class);
getApplicationContext().startActivity(myIntent);
https://stackoverflow.com/questions/47960014
复制相似问题