Bha*_*gav 1 android android-manifest android-intent android-service
这就是我的MainActivity和RecorderService Java类文件的样子.我也在添加AndroidManifest文件.
MainAcitivity.java
protected void onCreate(Bundle savedInstanceState) {
btnSendSOS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendSMS();
Intent intent = new Intent(getBaseContext(), RecorderService.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
new CountDownTimer(5000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
stopService(new Intent(getApplicationContext(), RecorderService.class));
}
}.start();
});
}
Run Code Online (Sandbox Code Playgroud)
RecorderService.java
public class RecorderService extends Service {
// Service code here
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:enabled="true"
android:name=".RecorderService" />
</application>
Run Code Online (Sandbox Code Playgroud)
我已将该服务添加到Manifest文件中.但我仍然得到错误:android.content.ActivityNotFoundException: Unable to find explicit activity class {.RecorderService}; have you declared this activity in your AndroidManifest.xml?
请帮帮我.提前致谢
RecorderService是服务.不是Activity.而且Start Service喜欢
Intent i = new Intent(MainActivity.this, RecorderService.class);
startService(i);
Run Code Online (Sandbox Code Playgroud)
进入官方文件以获取更多信息方面Services的安卓
| 归档时间: |
|
| 查看次数: |
2029 次 |
| 最近记录: |