首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Android Wear Watchface启动活动

从Android Wear Watchface启动活动
EN

Stack Overflow用户
提问于 2017-12-24 19:03:40
回答 1查看 834关注 0票数 1

我正在尝试在Android Wear中通过一个表盘启动一项活动,方法是:

代码语言:javascript
复制
            Intent myIntent = new Intent(this, com.jorc.android.wearable.watchface.watchface.MainActivity.class);
            getApplicationContext().startActivity(myIntent);

然而,我得到了这个错误。

代码语言:javascript
复制
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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-24 20:35:20

在使用Intent myIntent = new Intent(this,...MainActivity.class) MainActivity.class时,有一个小的缺失部分) intent是在另一个类中创建的,此处是一个匿名内部类画布,单击listener。代码并没有像预期的那样引用活动(或上下文)的实例,而是匿名内部类canvas ClickListener的实例。

因此,正确的方法是提供正确的类上下文。

代码语言:javascript
复制
 Intent myIntent = new Intent(DigitalWatchFaceService.this, com.jorc.android.wearable.watchface.watchface.MainActivity.class);
 getApplicationContext().startActivity(myIntent)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47960014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档