1 回答

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊
由于 Ahmed Ewiss 給出了正確答案,但沒有創(chuàng)建一個(gè)我可以接受的答案,使用他的建議,這對(duì)于其他人來說是一個(gè)簡單的模板,他們可以使用......
MAINACTIVITY.JAVA
package com.mycompany.rns;
imports are listed here...
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent k = new Intent(this,MyService.class);
startService(k);
}
}
我的服務(wù).JAVA
package com.mycompany.rns;
imports are listed here...
public class MyService extends IntentService {
public MyService(){
super("MyService");
}
@Override
protected void onHandleIntent(Intent intent) {
system.out.println("At fucking last!");
}
}
主文件
</activity>
<service
android:name=".MyService"
android:enabled="true"
android:exported="false" />
</application>
可行的解決方案是將 MainActivity.java 文件與 Service.java 文件分開。類文件。
添加回答
舉報(bào)