2017-12-24 28 views
-1

を着用してください。は、私が使用してクリック上のAndroid Wearにウォッチフェイスから活動を開始しようとしていますウォッチフェイス

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を使用します。

答えて

0

ここでは、意図は別のクラス内に作成された=新しいテント(これ、... MainActivity.class)MainActivity.class) 匿名内部クラスのキャンバスクリックリスナーを 意向myIntentを使用するときに小さな欠けている部分がありました。このコードは、アクティビティ(またはコンテキスト)のインスタンスを意図したものではなく、匿名の内部クラスのキャンバスのClickListenerのインスタンスを参照します。

正しい方法は、クラスの正しいコンテキストを提供することでした。

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

;

関連する問題