HI, Я пишу простое сервисное приложение, ниже приведен код Activity and Service .., когда я вызываю startService() и stopService() его работоспособность за один раз, в моем в случае, когда он должен дать уведомление. С следующего раза, если снова вызовет startService(), и stopService() не даст желаемых результатов ...проблема с сервисом
Пожалуйста, помогите мне в этом, если мне что-то не хватает .... ThanQ ,
---------- это мой класс деятельности ------------- package com.mypack.serviceex;
импорт android.app.Activity; импорт android.content.Intent; import android.os.Bundle; импорт android.util.Log; импорт android.view.View; import android.widget.Button;
public class serviceex extends Activity реализует Button.OnClickListener { /** Вызывается, когда действие сначала создается. */ Кнопка bt1, bt2; public void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.main);
bt1 = (Button) findViewById(R.id.Button01);
bt2 = (Button) findViewById(R.id.Button02);
bt1.setOnClickListener(this);
bt2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v == bt1)
{
Intent i = new Intent(serviceex.this,myservice.class);
Log.i("err","onClick(View v....");
startService(i);
}
else if(v == bt2)
{
Intent i = new Intent(serviceex.this,myservice.class);
Log.i("err","else if(v == bt2)........");
stopService(i);
}
}
}
--------- this is my service -------------
пакет com.mypack.serviceex;
импорт android.app.Notification; import android.app.NotificationManager; импорт android.app.PendingIntent; импорт android.app.Service; импорт android.content.Intent; импорт android.os.IBinder; импорт android.util.Log;
общественного класса MyService расширяет Услуги {
private NotificationManager nmgr;
public void onCreate()
{
super.onCreate();
nmgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Log.i("err","onCreate..........");
Thread th = new Thread(null,new incls(),"service...");
}
public void onStart(Intent intent,int sid)
{
super.onStart(intent, sid);
Log.i("err","onStart........");
}
public void onDestroy()
{
super.onDestroy();
Log.i("err","onDestroy..........");
displayMessage("Stopping Service");
}
public void displayMessage(String str)
{
Log.i("err.","displayMessage.....");
Notification nf = new Notification(R.drawable.icon,str,System.currentTimeMillis());
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this,myservice.class), 0);
nf.setLatestEventInfo(this, "Service...", str, pi);
nmgr.notify(R.string.uid, nf);
}
private class incls implements Runnable
{
public void run()
{
Log.i("err","public void run()..........");
System.out.println("In Runnn");
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
}
Какой уровень API вы нацеливаете? – codinguser
Я занимаюсь уровнем 2.1 – Brigadier