Hi, I am new to android Development. I have created a location based application which runs in the Background. I dont get any errors but when i try to check it out using emulator. I get a message saying that the applicataion has stopped unexpectedly, Pls try again. Can some one help me out with this problem.
Service File: package com.Location.LBS; import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.os.Bundle; import android.telephony.TelephonyManager; import android.telephony.gsm.GsmCellLocation; import android.util.Log; import android.widget.Toast; import android.os.Handler; class BackgroundServiceTask implements Runnable{ private static final String LOG_TAG="BackgroundService"; private Handler serviceHandler; private int countDown = 0; private long interval= 0L; public BackgroundServiceTask(int countDown, long interval, Handler serviceHandler) { this.countDown = countDown; this.interval = interval; this.serviceHandler = serviceHandler; } public void run() { Log.d(LOG_TAG,"Counter:"+ countDown); if(--countDown > 0) serviceHandler.postDelayed(this, interval); } } public class MyService extends Service { private static final String LOG_TAG ="Background Service"; private Handler serviceHandler = new Handler(); private static final int COUNTDOWN_LIMIT = 10; private static final long COUNTDOWN_INTERVAL = 3*1000L; protected void onStart(int startId,Bundle arguments) { super.onStart(null , startId); Log.d(LOG_TAG,"onstart"); GsmCellLocation location; int cellID, lac; final String latLongString; TelephonyManager tm = (TelephonyManager)getSystemService (Context.TELEPHONY_SERVICE); location = (GsmCellLocation) tm.getCellLocation(); if(location != null) { cellID =location.getCid(); lac = location.getLac(); latLongString="CellID:"+ 2675+"\n Lac:"+8894; Log.i(getClass().getSimpleName(), "Data From Location:" + latLongString); Toast.makeText(this,"Location:"+latLongString , Toast.LENGTH_SHORT); } else { latLongString ="No Location found"; } BackgroundServiceTask bst = new BackgroundServiceTask (COUNTDOWN_LIMIT, COUNTDOWN_INTERVAL, serviceHandler); serviceHandler.postDelayed(bst,COUNTDOWN_INTERVAL); stopSelf(); } public void onDestroy() { super.onDestroy(); Log.d(LOG_TAG, "onDestory"); } @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } } Broadcast receiver file: package com.Location.LBS; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; //import android.os.Bundle; import android.content.ComponentName; import android.util.Log; public class BootCompletedIntentReceiver extends BroadcastReceiver { private static final String LOG_TAG ="BootCompletedIntentReceiver"; public BootCompletedIntentReceiver() { // TODO Auto-generated constructor stub } @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); Log.d(LOG_TAG, action); if(action== null) Log.e(LOG_TAG,"Action==null!"); else if("android.intent.action.BOOT_COMPLETED".equals(action)) { Intent i = new Intent(); i.setClassName("com.Location.LBS","com.Location.LBS.MyService"); ComponentName cname = context.startService(i); if(cname == null) Log.e(LOG_TAG, "Background Service was not Started!"); else Log.d(LOG_TAG, "Background Service Started"); } } } Activity File: package com.Location.LBS; import android.app.Activity; import android.os.Bundle; import android.content.Intent; public class LocationFinder extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); Intent i = new Intent(); i.setClassName("com.Location.LBS", "com.Location.LBS.MyService"); startService(i); } } Manifest File: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.Location.LBS" android:versionCode="1" android:versionName="1.0.0"> <application android:icon="@drawable/icon" android:label="@string/ app_name"> <activity android:name=".LocationFinder" 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:permission="android.permission.ACCESS_COARSE_LOCATION" android:enabled="true" android:name="MyService"></service> <receiver android:name="BootCompletedIntentReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"></ receiver> </application> </manifest> Thanks & Regards, Pawan Kumar Venugopal --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---