从Android Wear Watchface开始活动

问题描述 投票:0回答:1

我试图通过点击使用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.Engine扩展CanvasWatchFaceService。

wear-os watch-face-api
1个回答
2
投票

使用Intent myIntent = new Intent时出现了一个小小的缺失部分(这,... MainActivity.class)MainActivity.class)意图是在另一个类中创建的,这里是一个匿名的内部类画布点击监听器。代码不会按预期引用Activity(或Context)的实例,而是引用匿名内部类canvas JakListener的实例。

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

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

;

© www.soinside.com 2019 - 2024. All rights reserved.