Hai我有一個應用程序,使用後臺service.its運行清晰。如果我的手機關閉,我的服務是關閉service.when我的應用程序啓動後,只有我的後臺服務被陳述。我想重新啓動服務時再次手機關機了? 有可能嗎? 任何人只要有代碼如何在移動設備打開時在android中啓動應用程序?
更新
public class loginForm extends Activity
{
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.login);
receiver = new ConnectionReceiver();
registerReceiver(receiver,new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
}
private class ConnectionReceiver extends BroadcastReceiver{
private Timer mTimer;
private TimerTask mTimerTask;
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra (ConnectivityManager.EXTRA_NETWORK_INFO);
if(null != info)
{
String state = getNetworkStateString(info.getState());
if(state.equals("Connected")){
mTimer = new Timer();
mTimerTask = new TimerTask() {
@Override
public void run() {
loginForm.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//Toast.makeText(getBaseContext(), "Disenabled provider " + provider,
///Toast.LENGTH_SHORT).show();
try{
insertAllGpsInformation();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), "Your Net Connected or Not Login to Net"+"", Toast.LENGTH_LONG).show();
Log.e("Upload Picture Error:",e.getMessage());
}
}
});
}
};
mTimer.scheduleAtFixedRate(mTimerTask,180000,180000);
}
}
}
}
}
receiver = new ConnectionReceiver(); registerReceiver(receiver,new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));開始我的服務,像這樣,我的 category android:name =「android.intent。 category.HOME「> intent-filter>我的清單文件。但我的服務不是staretd。 –
Mercy
2012-01-13 09:47:39