장치 부팅시 응용 프로그램을 시작하려고합니다. MySQL 데이터베이스에 데이터를 전송 백그라운드 스레드 (AsyncTask를)를 포함장치 부팅시 작업을 시작하는 서비스 시작
1 개 먼저 기본 클래스를 다음과 같이
내 코드입니다.
2- 서비스 클래스
package com.seven.ex.helper;
import com.seven.ex.AndroidGPSTrackingActivity;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class service extends Service {
private static final String TAG = "MyService";
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void onDestroy() {
Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
Log.d(TAG, "onDestroy");
}
@Override
public void onStart(Intent intent, int startid)
{
Intent intents = new Intent(getBaseContext(),AndroidGPSTrackingActivity.class);
intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intents);
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
}
}
-3- BootUpReceiver 클래스
package com.seven.ex.helper;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootUpReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context arg0, Intent arg1) {
Intent intent = new Intent(arg0,service.class);
arg0.startService(intent);
Log.i("Autostart", "started");
}
}
4- 안드로이드 매니페스트 파일
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpstracking"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.seven.gpstracking.AndroidGPSTrackingActivity"
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:name=".service"
android:label="@string/app_name"
>
</service>
<receiver android:enabled="true" android:name=".BootUpReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
내가 시작하려하기 전에 주요 방법은 올바르게 작동 부팅 중입니다. 내가 예외
당신이 도움을 주시기 바랍니다 수없는 클래스를 얻고 로그 고양이 부트 (앱 청산)
에 안드로이드 오류를 무시 후 또한 응용 프로그램은 여전히 작동?
코드가 서비스 또는 AndroidGPSTrackingActivity 클래스를 찾지 못합니까? – cYrixmorten
에뮬레이터를 부팅 할 때 강제 종료 오류가 나타납니다. 아이콘을 클릭하여 응용 프로그램을 열면 부드럽게 작동합니다. logcat 표시 아무것도 때까지 아이콘을 클릭하여 응용 프로그램을 열었습니다 – Seven
이해하지만, 당신은 "로그 cat에서 예외를 찾을 수 없습니다 클래스를 받고"작성하고 어떤 클래스를 찾을 수 실패 알고 싶습니다. – cYrixmorten