Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java/Android共享首选项-不指向正确的活动_Java_Android_Sharedpreferences - Fatal编程技术网

Java/Android共享首选项-不指向正确的活动

Java/Android共享首选项-不指向正确的活动,java,android,sharedpreferences,Java,Android,Sharedpreferences,当我的应用程序第一次启动时,我希望将用户引导到字符串的配置类型。我正在使用共享首选项来执行此操作。当用户第一次运行应用程序时,共享首选项文件应为空。它首先检查是否存在与键“configured”关联的布尔值。如果没有,它应该重定向到名为preferences的活动。然而,它似乎只是“跳过”了这一点;而不是直接进行午餐或早餐活动。我甚至尝试过清除共享的首选项,但都无济于事。你知道问题是什么吗 开展活动 import android.app.AlarmManager; import android.

当我的应用程序第一次启动时,我希望将用户引导到字符串的配置类型。我正在使用共享首选项来执行此操作。当用户第一次运行应用程序时,共享首选项文件应为空。它首先检查是否存在与键“configured”关联的布尔值。如果没有,它应该重定向到名为preferences的活动。然而,它似乎只是“跳过”了这一点;而不是直接进行午餐或早餐活动。我甚至尝试过清除共享的首选项,但都无济于事。你知道问题是什么吗

开展活动

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;



import java.util.Calendar;
import java.util.GregorianCalendar;


public class launch_activity extends AppCompatActivity {

// private PendingIntent pending;

/*public void startAlarm() {
    AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
    GregorianCalendar greg = new GregorianCalendar();
    Calendar now = Calendar.getInstance();
    greg.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), 10, 30);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, greg.getTimeInMillis(), 1000 * 60 * 60 * 24, pending);
}*/

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launch_activity);

        // set alarm
       // Intent alarmIntent = new Intent(this, alarmReceiver.class);
        // pending = PendingIntent.getBroadcast(launch_activity.this, 0, alarmIntent, 0);
        // startAlarm();




    }

    protected void onStart() {
        super.onStart();
        SharedPreferences preferences = getSharedPreferences("config", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();

        if((preferences.getBoolean("configured", false)) == false) { // app has not yet been set-up
            Intent intent = new Intent(this, midamcorp.com.burgerkingapp.preferences.class);
            intent.putExtra("setUp", true);
            startActivity(intent);
        }
        Calendar cal = Calendar.getInstance();
        if(cal.get(Calendar.HOUR_OF_DAY) > 4 && (cal.get(Calendar.HOUR_OF_DAY) <= 10  && cal.get(Calendar.MINUTE) < 28))
        {

            Intent intent = new Intent(this, breakfastHome.class);
            startActivity(intent);
        } else {
            Intent intent = new Intent(this, lunchHome.class);
            startActivity(intent);
        }
    }

    protected void onResume() {
        super.onResume();
        SharedPreferences preferences = getSharedPreferences("config", MODE_PRIVATE);

        if(!(preferences.getBoolean("configured", false))) { // app has not yet been set-up
            Intent intent = new Intent(this, midamcorp.com.burgerkingapp.preferences.class);
            intent.putExtra("setUp", true);
            startActivity(intent);
        }
        Calendar cal = Calendar.getInstance();
        if(cal.get(Calendar.HOUR_OF_DAY) > 4 && (cal.get(Calendar.HOUR_OF_DAY) <= 10  && cal.get(Calendar.MINUTE) < 28))
        {

            Intent intent = new Intent(this, breakfastHome.class);
            startActivity(intent);
        } else {
            Intent intent = new Intent(this, lunchHome.class);
            startActivity(intent);
        }

    }
}

非常感谢

您始终运行以下代码:

        Calendar cal = Calendar.getInstance();
    if(cal.get(Calendar.HOUR_OF_DAY) > 4 && (cal.get(Calendar.HOUR_OF_DAY) <= 10  && cal.get(Calendar.MINUTE) < 28))
    {

        Intent intent = new Intent(this, breakfastHome.class);
        startActivity(intent);
    } else {
        Intent intent = new Intent(this, lunchHome.class);
        startActivity(intent);
    }
Calendar cal=Calendar.getInstance();

如果(cal.get(Calendar.HOUR\u OF_DAY)>4&&(cal.get(Calendar.HOUR\u OF_DAY))4&&(cal.get(Calendar.HOUR\u OF_DAY)您似乎在启动时开始了两项活动

如果出现以下情况,只需在您的第一张支票上添加“退货”:

    if((preferences.getBoolean("configured", false)) == false) { // app has not yet been set-up
        Intent intent = new Intent(this, midamcorp.com.burgerkingapp.preferences.class);
        intent.putExtra("setUp", true);
        startActivity(intent);
    } 
    else {
        Calendar cal = Calendar.getInstance();
        if(cal.get(Calendar.HOUR_OF_DAY) > 4 && (cal.get(Calendar.HOUR_OF_DAY) <= 10  && cal.get(Calendar.MINUTE) < 28))
        {

            Intent intent = new Intent(this, breakfastHome.class);
            startActivity(intent);
        } else {
            Intent intent = new Intent(this, lunchHome.class);
            startActivity(intent);
        }
    }
               if((preferences.getBoolean("configured", false)) == false) { // app has not yet been set-up
                    Intent intent = new Intent(this, midamcorp.com.burgerkingapp.preferences.class);
                    intent.putExtra("setUp", true);
                    startActivity(intent);
                    return; //HERE----------------------------------
                }
                Calendar cal = Calendar.getInstance();
                if(cal.get(Calendar.HOUR_OF_DAY) > 4 && (cal.get(Calendar.HOUR_OF_DAY) <= 10  && cal.get(Calendar.MINUTE) < 28))
                {

                    Intent intent = new Intent(this, breakfastHome.class);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(this, lunchHome.class);
                    startActivity(intent);
                }
if((preferences.getBoolean(“configured”,false))==false){//app尚未设置
Intent Intent=新Intent(这个,midmacorp.com.burgerkingapp.preferences.class);
intent.putExtra(“设置”,真);
星触觉(意向);
return;//在这里----------------------------------
}
Calendar cal=Calendar.getInstance();
如果(cal.get(日历小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时小时
               if((preferences.getBoolean("configured", false)) == false) { // app has not yet been set-up
                    Intent intent = new Intent(this, midamcorp.com.burgerkingapp.preferences.class);
                    intent.putExtra("setUp", true);
                    startActivity(intent);
                    return; //HERE----------------------------------
                }
                Calendar cal = Calendar.getInstance();
                if(cal.get(Calendar.HOUR_OF_DAY) > 4 && (cal.get(Calendar.HOUR_OF_DAY) <= 10  && cal.get(Calendar.MINUTE) < 28))
                {

                    Intent intent = new Intent(this, breakfastHome.class);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(this, lunchHome.class);
                    startActivity(intent);
                }