【问题标题】:Starting an Activity from Android Wear Watchface从 Android Wear Watchface 启动 Activity
【发布时间】:2017-12-24 11:03:39
【问题描述】:

我正在尝试通过点击从 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】:

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

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

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

    ;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多