我在我的应用程序中设置onStart方法时遇到问题.它总是有一个删除线,说"这个方法在API级别5中已被弃用.我需要onStart,而不是onStartCommand.
我该如何解决这个问题?
MyNotificationService.java
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyNotificationService extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Toast.makeText(this, "OnCreate()", Toast.LENGTH_SHORT).show();
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "OnDestroy()", Toast.LENGTH_SHORT).show();
}
@Override
@Deprecated
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
}
}
Run Code Online (Sandbox Code Playgroud)
Reminder_2.java …
看来,当涉及到*value.getFloat("Value_Quotient",quotient_Float)== null*时,它遇到了一个问题.我该如何解决?
private void Store() {
quotient_Float = posture_error/time;
if(value.getFloat("Value_Quotient", quotient_Float)==null || quotient_Float < value.getFloat("Value_Quotient", quotient_Float))
{
editor.putFloat("Value_Quotient", quotient_Float);
editor.commit();
}
}
Run Code Online (Sandbox Code Playgroud) 如何在Android应用中保存变量值?值可以保存在内存中吗?我打算在我的应用程序中保存一个float值,因此下次打开该应用程序时,将加载以前的值。我该怎么办?共享首选项还是其他?