我正在开发一个包含Spinner的应用程序。我希望它:检测依赖于Spinner的int更改,如果此值=不为0,则需要创建一个String并使用int值对其进行实例化。
这是Hider.class代码:(服务)
public int NOTIF_ID =1;
public double timeup;
public static String time;
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public int onStartCommand(Intent argument, int flags, int startId)
{
Toast.makeText(getApplicationContext(),"Service Started", Toast.LENGTH_SHORT).show();
NotificationManager notif_manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder notif_specs = new Notification.Builder(this);
notif_specs.setContentTitle("Notification");
notif_specs.setContentText("is now active..."+ timeup);
notif_specs.setSmallIcon(R.drawable.combo);
notif_specs.setTicker("Bildirim Geldi");
notif_specs.setOngoing(true);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent bildirimin_niyeti = PendingIntent.getActivity(this, NOTIF_ID, intent, 0);
notif_specs.setContentIntent(bildirimin_niyeti);
final Notification notif = notif_specs.getNotification();
notif_manager.notify(NOTIF_ID, notif);
if (MainActivity.timer_time!=0)
{
String str;
switch (MainActivity.timer_time)
{
case 1: str = "Remaining 1m";
break;
case 5: str = "Remaining 5m";
break;
case 10: str = "Remaining 10m";
break;
}
}
return START_STICKY;
}
public void onDestroy()
{
NotificationManager notif_mani = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notif_mani.cancel(NOTIF_ID);
if(MainActivity.vib_bool)
{
final MediaPlayer oynatıcı = MediaPlayer.create(this, R.drawable.end);
oynatıcı.start();
}
Toast.makeText(getApplicationContext(),"Service Stopped",Toast.LENGTH_SHORT).show();
super.onDestroy();
}
}
这段代码不工作导致OnStartCommand()工作一次我想。那么如何编写这段代码来重复运行呢? 谢谢你的帮助。