Hello,
In the documentation of stopService it is written:
"Note that if a stopped service still has ServiceConnection objects
bound to it with the BIND_AUTO_CREATE set, it will not be destroyed
until all of these bindings are removed."
However since I have an unbound local service I thought, that my
service is not bound to anything and if that is not corret then at
least it should be unbound after invoking stopService.
My Activity:
package de.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class SimpleServiceActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonOn = (Button)findViewById(R.id.buttonOn);
buttonOn.setOnClickListener(mButtonOnListener);
Button buttonOff = (Button)findViewById(R.id.buttonOff);
buttonOff.setOnClickListener(mButtonOffListener);
}
private OnClickListener mButtonOnListener = new OnClickListener()
{
public void onClick(View v) {
startService(new Intent(SimpleServiceActivity.this,
MyService.class));
}
};
private OnClickListener mButtonOffListener = new OnClickListener()
{
public void onClick(View v) {
stopService(new Intent(SimpleServiceActivity.this,
MyService.class));
}
};
}
My Service:
package de.test;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service {
private Timer mTimer;
private TimerTask mTimerTask = new TimerTask() {
public void run() {
Log.d("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
};
@Override
public void onCreate() {
this.mTimer = new Timer();
this.mTimer.schedule(mTimerTask, 0, 1000);
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
Mainfest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<activity android:name=".SimpleServiceActivity"
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:name=".MyService"/>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
The Log.d invocation goes on after pressing buttonOff ...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---