从Android Wear Watchface开始活动 [英] Starting an Activity from Android Wear Watchface

查看:105
本文介绍了从Android Wear Watchface开始活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令从Android Wear的表面开始一项活动:

I am trying to start an activity from a watchface in Android Wear on a click using:

            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.

My question is: "Is there a way to start an activity from a watchface"? Watchface uses CanvasWatchFaceService.Engine which extends CanvasWatchFaceService.

推荐答案

使用时缺少一小部分 意图myIntent =新意图(this,... MainActivity.class)MainActivity.class) 该意图是在另一个类内部创建的,这里是一个匿名内部类画布单击侦听器.该代码未按预期引用Activity(或Context)的实例,而是匿名内部类canvas ClickListener的实例.

There was a small missing part when using Intent myIntent = new Intent(this, ...MainActivity.class) MainActivity.class) The intent is created inside another class, here an anonymous inner class canvas click listener. The code does not refer the instance of the Activity (or Context) as intended but the instance of the anonymous inner class canvas ClickListener.

所以正确的方法是提供正确的类上下文.

So the right way was to provide the correct context of class.

 Intent myIntent = new Intent(DigitalWatchFaceService.this, com.jorc.android.wearable.watchface.watchface.MainActivity.class);
 getApplicationContext().startActivity(myIntent)

;

这篇关于从Android Wear Watchface开始活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆