小编Chr*_*nor的帖子

在Android中,如何避免onStart方法被弃用?

我在我的应用程序中设置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 …

service notifications android onstart deprecated

27
推荐指数
1
解决办法
2万
查看次数

在Java中,如何检查float变量是否为空?

看来,当涉及到*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)

java variables null android

8
推荐指数
2
解决办法
3万
查看次数

即使关闭应用程序后,也可以在Android中(在内存中)保存变量值吗?如果是这样,怎么办?

如何在Android应用中保存变量值?值可以保存在内存中吗?我打算在我的应用程序中保存一个float值,因此下次打开该应用程序时,将加载以前的值。我该怎么办?共享首选项还是其他?

memory variables storage android

5
推荐指数
1
解决办法
5504
查看次数