I get a timeout on the Service, so maybe it is running, I just don't
get a reference to it.
07-29 22:17:15.485: WARN/WindowManager(166): Force clearing freeze:
AppWindowToken{46ad1860 token=HistoryRecord{465c3f50
nl.kransen.consumption.android/.ViewTrendActivity}}
07-29 22:17:17.625: DEBUG/dalvikvm(166): GC freed 14677 objects /
990168 bytes in 142ms
07-29 22:17:19.921: WARN/ActivityManager(166): Launch timeout has
expired, giving up wake lock!
07-29 22:17:20.599: WARN/ActivityManager(166): Activity idle timeout
for HistoryRecord{465c3f50
nl.kransen.consumption.android/.ViewTrendActivity}
07-29 22:17:25.685: DEBUG/dalvikvm(11731): GC freed 3116 objects /
286000 bytes in 82ms
07-29 22:17:34.597: DEBUG/AndroidRuntime(1139): Shutting down VM
07-29 22:17:34.597: WARN/dalvikvm(1139): threadid=3: thread exiting
with uncaught exception (group=0x4001b390)
07-29 22:17:34.606: ERROR/AndroidRuntime(1139): Uncaught handler:
thread main exiting due to uncaught exception
07-29 22:17:34.656: ERROR/AndroidRuntime(1139):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{nl.kransen.consumption.android/
nl.kransen.consumption.android.ViewTrendActivity}:
java.lang.NullPointerException
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2596)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2621)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.app.ActivityThread.access$2200(ActivityThread.java:126)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.os.Handler.dispatchMessage(Handler.java:99)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.os.Looper.loop(Looper.java:123)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.app.ActivityThread.main(ActivityThread.java:4595)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
java.lang.reflect.Method.invokeNative(Native Method)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
java.lang.reflect.Method.invoke(Method.java:521)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
dalvik.system.NativeStart.main(Native Method)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): Caused by:
java.lang.NullPointerException
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
nl.kransen.consumption.android.ViewTrendActivity.onCreate(ViewTrendActivity.java:
44)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2544)
07-29 22:17:34.656: ERROR/AndroidRuntime(1139): ... 11 more
On 29 jul, 22:13, Jeroen Kransen <jer...@kransen.nl> wrote:
> Please help anybody. I create a local service in the simplest possible
> way, but when I bind to it, the reference remains null. Did I find a
> bug anywhere? I am developing from Eclipse with lib and target
> platform 2.1 update 1 (although other versions did not make a
> difference).
>
> My activity is like this:
>
> public class ViewTrendActivity extends Activity {
>
> private ConsumptionService consumptionService = null;
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> bindService(new Intent(this, ConsumptionService.class),
> serviceConnection, BIND_AUTO_CREATE);
> String blah = consumptionService.doBlah();
> }
>
> }
>
> This is the Service:
>
> public class ConsumptionService extends Service {
>
> public String doBlah() {
> return "blah";
> }
>
> // stuff to make this an Android Service
>
> private final Binder binder = new LocalBinder();
>
> @Override
> public IBinder onBind(Intent intent) {
> return binder;
> }
>
> public class LocalBinder extends Binder {
> public ConsumptionService getService() {
> return (ConsumptionService.this);
> }
> }
>
> }
>
> This is the definition in the Manifest:
>
> <service android:name=".service.ConsumptionService" />
>
> I want a local Service, so I do not define any process.
>
> Is there anything missing here?
>
> Jeroen
>
> On 28 jul, 11:53, Jeroen Kransen <jer...@kransen.nl> wrote:
>
> > Thanks, Mark!
>
> > My code is basically the same as yours. I downloaded your project, and
> > guess what, that too did not work with me! I'm sure it works for you,
> > so I'm thinking my setup is broken somewhere.
>
> > LogCat does not mention any service being started, neither with my,
> > nor with your app. An error that I always get (with working apps as
> > well, and often more than one) is this:
>
> > 07-28 11:43:12.608: ERROR/AndroidRuntime(27800): ERROR: thread attach
> > failed
>
> > In debug mode, I see that the Service reference remains null in both
> > our apps. However, I do see lots of logging related to GPS, so I think
> > the Service does run. I just don't get a reference to it.
>
> > I really feel lost now. It should not be this difficult to do
> > something this simple...
>
> > Jeroen
>
> > On 28 jul, 05:18, Mark Murphy <mmur...@commonsware.com> wrote:
>
> > > Examine LogCat and see if you have any warnings.
>
> > > Also, in case it helps, here is a sample project demonstrating the technique:
>
> > >http://github.com/commonsguy/cw-android/tree/master/Service/WeatherPlus/
>
> > > On Tue, Jul 27, 2010 at 10:54 PM, Jeroen Kransen <jer...@kransen.nl> wrote:
> > > > I want to use a local service to fence off some logic in a singleton
> > > > class. From my Activities I try to bind to it. The method
> > > > bindService() returns true, but the Service onCreate() is never
> > > > called, nor is the ServiceConnector's onServiceConnected().
>
> > > > Please tell me what part I am missing.
>
> > > > Here is my manifest snippet (note that I do not set :remote, as I want
> > > > the service to be local):
>
> > > > <service android:enabled="true"
> > > > android:name=".service.ConsumptionService"/>
>
> > > > This is how I call the ServiceConnector and the Service:
>
> > > > Intent serviceIntent = new Intent(this, ConsumptionService.class);
> > > > ConsumptionServiceConnection serviceConnection = new
> > > > ConsumptionServiceConnection();
> > > > boolean isBound = bindService(serviceIntent, serviceConnection,
> > > > Context.BIND_AUTO_CREATE);
>
> > > > Especially the "BIND_AUTO_CREATE" part should to the creation,
> > > > according to the documentation.
>
> > > > This is the Service itself:
>
> > > > @Override
> > > > public void onCreate() {
> > > > super.onCreate();
> > > > measurementDao = new MeasurementDaoImpl(this);
> > > > calculator = new TrendCalculatorImpl(measurementDao);
> > > > }
>
> > > > @Override
> > > > public IBinder onBind(Intent intent) {
> > > > return binder;
> > > > }
>
> > > > public class LocalBinder extends Binder {
> > > > ConsumptionService getService() {
> > > > return ConsumptionService.this;
> > > > }
> > > > }
>
> > > > private final IBinder binder = new LocalBinder();
>
> > > --
> > > Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> > > _Android Programming Tutorials_ Version 2.9 Available!
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment