[英]How to use Android Service from other project?
我想使用一個實現為Android服務的外部項目。 通過將服務添加到清單中來使用該服務:
<service android:name="com.my.ext.service"/>
但是當我添加此行時,出現錯誤:
Unresolved class 'TimerService' less... (⌘F1)
Validates resource references inside Android XML files.
當我在項目中添加布局時:
<com.my.ext.service
android:id="@+id/myview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
我得到的錯誤
the class could not be found
我已經將外部服務作為一個額外的項目導入了我的Android Studio。 如何將另一個項目用作該項目的服務?
您不能將您的服務類用作XML布局。 您可以使用以下服務
<service android:name="com.my.ext.service"/>
並使用以下命令從您應用的主要活動中執行該服務:
private Intent OtherService;
OtherService = new Intent((Context)this, (Class)YOURSERVICE.class);
MainActivity.this.startService(MainActivity.this.OtherService);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.