startActivity() is not defined where you are trying to call it from. It is a method on the Context class.
Create a constructor for your CallStateListener class that takes a Context object as a parameter and store it as a member variable. When you create a new instance of your class, you can do the following line of code instead since Service extends Context: CallStateListener mCallStateListener = new CallStateListener(this); Then, assuming your Context object is called m_context, you can do this to start your activity: m_context.startActivity(intentToLaunchNote); Hope this helps! Thanks, Justin ---------------------------------------------------------------------- There are only 10 types of people in the world... Those who know binary and those who don't. ---------------------------------------------------------------------- On Tue, Nov 3, 2009 at 2:00 PM, Tabibito <[email protected]> wrote: > Hi all, > I've begun creating a "Call Notes" application that runs as a service > from startup, senses when a call has ended, and pops up a screen where > you can put in a note about the call. So far I have gotten the > service to start on boot, the service senses the hangup, but when it > does, I can't get it to start up the activity that will allow it to > accept a note. It insists that in the place I call startActivity(), > the function is not defined, and none of the various ways I have tried > to call it seem to work... Here's what I've got so far, with the > problematic call to startActivity() noted with comments at the > bottom. I have implemented NotePad.java too, but it doesn't seem to > be getting that far... Thanks in advance to anyone who can point me in > the right direction! > > > Manifest: > ======================================================================== > <?xml version="1.0" encoding="utf-8"?> > <manifest xmlns:android="http://schemas.android.com/apk/res/android" > package="com.lyrix.mobiso" > android:versionCode="1" > android:versionName="1.0"> > <application android:icon="@drawable/icon" android:label="@string/ > app_name"> > > <activity android:name="com.lyrix.mobiso.NotePad" > android:label="@string/app_name"> > <intent-filter> > <action android:name="com.lyrix.mobiso.CALLNOTE" /> > </intent-filter> > </activity> > > <receiver android:name="com.lyrix.mobiso.onBootReceiver"> > <intent-filter> > <action > android:name="android.intent.action.BOOT_COMPLETED" /> > </intent-filter> > </receiver> > > <service android:name="com.lyrix.mobiso.ServiceManager"> > <intent-filter> > <action > android:name="com.lyrix.mobiso.MY_SERVICE" /> > </intent-filter> > </service> > > </application> > > <uses-sdk android:minSdkVersion="3" /> > <uses-permission android:name="android.permission.READ_CONTACTS" /> > <uses-permission android:name="android.permission.READ_PHONE_STATE" > / > > > <uses-permission > android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> > </manifest> > > onBootReceiver.java > ================================================================ > package com.lyrix.mobiso; > > import android.content.BroadcastReceiver; > import android.content.Context; > import android.content.Intent; > > public class onBootReceiver extends BroadcastReceiver { > @Override > public void onReceive(Context context, Intent intent) { > Intent myIntent = new Intent(); > myIntent.setAction("com.lyrix.mobiso.MY_SERVICE"); > context.startService(myIntent); > } > } > > ServiceManager.java > ================================================================ > package com.lyrix.mobiso; > > import com.lyrix.mobiso.CallStateListener; > import android.app.Service; > import android.content.Context; > import android.content.Intent; > import android.os.IBinder; > import android.telephony.PhoneStateListener; > import android.telephony.TelephonyManager; > import android.util.Log; > > public class ServiceManager extends Service { > /** Called when the service is first created. */ > @Override > public void onCreate() { > super.onCreate(); > // Register onCallStateChanged listener... > CallStateListener mCallStateListener = new CallStateListener > (); > TelephonyManager tm = (TelephonyManager)this.getSystemService > (Context.TELEPHONY_SERVICE); > try{ > tm.listen(mCallStateListener, > PhoneStateListener.LISTEN_CALL_STATE); > }catch(Exception e){ > Log.d("DEBUG", "Got an error > listening:"+e.getLocalizedMessage > ()); > } > Log.d("DEBUG", "Listening..."); > } > > public IBinder onBind(Intent intent) { > return null; > } > } > > CallStateListener.java > ============================================================== > package com.lyrix.mobiso; > > import android.content.Context; > import android.content.Intent; > import android.telephony.PhoneStateListener; > import android.telephony.TelephonyManager; > import android.util.Log; > import android.app.Activity; > import android.app.Service; > > public class CallStateListener extends PhoneStateListener > { > @Override > public void onCallStateChanged(int state, String incomingNumber) > { > if(state == TelephonyManager.CALL_STATE_IDLE){ > Log.d("DEBUG", "===================JUST WENT > IDLE====================="); > Intent intentToLaunchNote = new Intent(); > > intentToLaunchNote.setAction("com.lyrix.mobiso.CALLNOTE"); > > intentToLaunchNote.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); > > // THIS IS THE PLACE THAT ECLIPSE COMPLAINS ABOUT... > // SAYS THE METHOD IS UNDEFINED FOR THE TYPE CallStateListener... > > startActivity(intentToLaunchNote); > } > } > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-beginners%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

