Created
July 12, 2011 17:55
-
-
Save anonymous/1078544 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.service.gpsApp" | |
android:versionCode="1" | |
android:versionName="1.0"> | |
<uses-sdk android:minSdkVersion="10" /> | |
<application android:icon="@drawable/icon" android:label="@string/app_name"> | |
<receiver android:name=".StartUpApp"> | |
<intent-filter> | |
<action android:name="android.intent.action.BOOT_COMPLETED" /> | |
</intent-filter> | |
</receiver> | |
<service android:name=".ServiceAppActivity"></service> | |
</application> | |
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.service.gpsApp; | |
import android.app.Service; | |
import android.content.Intent; | |
import android.os.Handler; | |
import android.os.IBinder; | |
import android.util.Log; | |
public class ServiceAppActivity extends Service { | |
private Handler handler = new Handler(); | |
@Override | |
public IBinder onBind(Intent intent) { | |
return null; | |
} | |
@Override | |
public int onStartCommand(Intent intent, int flags,int startId) | |
{ | |
Log.e("On","Start"); | |
handler.postDelayed(doSomething,2000); | |
return START_STICKY; | |
} | |
@Override | |
public void onDestroy() | |
{ | |
handler.removeCallbacks(doSomething); | |
Log.e("On","Destroy"); | |
super.onDestroy(); | |
} | |
public static int count = 0; | |
private Runnable doSomething = new Runnable(){ | |
public void run() | |
{ | |
Log.e("Try","I'm here"); | |
count++; | |
Log.e("count",String.valueOf(count)); | |
handler.postDelayed(doSomething,2000); | |
} | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.service.gpsApp; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
public class StartUpApp extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// TODO Auto-generated method stub | |
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) | |
{ | |
Intent serviceIntent = new Intent(context, ServiceAppActivity.class); | |
context.startService(serviceIntent); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment