启动画面后,Android App不会继续播放

时间:2016-10-09 10:38:41

标签: android android-activity

美好的一天

我最近遇到了一个问题,即我的应用程序在启动画面后没有继续显示主活动。它在第一次安装时进入主活动但在此之后它不再存在。

我查看过这两篇文章: token=android.os.BinderProxy error android? Timer stops working after app resume (Android)

他们都没有完全回答这个问题,与我的例子不同。

基本上,此人需要接受EULA才能进入主要活动。如果他们在没有接受EULA的情况下退出应用程序,它会在再次进入时转移到它。

以下是活动代码:

public class Splash extends AppCompatActivity {

boolean a;

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


    final SharedPreferences settings = getSharedPreferences("prefs", 0);
    final boolean firstRun = settings.getBoolean("firstRun", false);
    final SharedPreferences disc = getSharedPreferences("disc", 0);
    final boolean disclaimer = disc.getBoolean("disclaimer", false);


    Thread thread = new Thread() {
        @Override
        public void run() {

            try {
                sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {


                if (!firstRun) {
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putBoolean("firstRun", true);
                    editor.apply();
                    Intent i = new Intent(Splash.this, Instruction.class);
                    startActivity(i);
                    finish();


                } else {
                    try {
                        Bundle bundle = getIntent().getExtras();
                        a = bundle.getBoolean("key");

                        if (a == true) {
                            SharedPreferences.Editor editor = disc.edit();
                            editor.putBoolean("disclaimer", true);
                            editor.apply();

                            Intent i = new Intent(Splash.this, siteCheck.class);
                            startActivity(i);
                        }
                    } catch (Exception e) {

                        if (disclaimer == true) {
                            Intent i = new Intent(Splash.this, siteCheck.class);
                            startActivity(i);
                        } else {
                            Intent d = new Intent(Splash.this, Instruction.class);
                            startActivity(d);
                        }

                    }
                }

            }
        }


    };
    thread.start();


}

@Override
protected void onPause() {
    super.onPause();
    finish();

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.global, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement


    return super.onOptionsItemSelected(item);
}

}

LogCat如下:

10-09 12:26:36.820 10246-10246/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@279459f time:16608813

这是它结束的消息。它不会从那里继续,而只是停留在启动画面上。

它可能与我使用Thread有什么关系吗?如果那时,为什么只是现在而不是早期的发展。

我非常感谢任何帮助,指导或建议。

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

使用以下代码从splashScreen启动您的活动:请注意finish();也应该叫做

 Handler h = new Handler(Looper.getMainLooper());
    h.postDelayed(() -> {
       if (!firstRun) {
                SharedPreferences.Editor editor = settings.edit();
                editor.putBoolean("firstRun", true);
                editor.apply();
                Intent i = new Intent(Splash.this, Instruction.class);
                startActivity(i);
                finish();
            } else {
                try {
                    Bundle bundle = getIntent().getExtras();
                    a = bundle.getBoolean("key");

                    if (a == true) {
                        SharedPreferences.Editor editor = disc.edit();
                        editor.putBoolean("disclaimer", true);
                        editor.apply();

                        Intent i = new Intent(Splash.this, siteCheck.class);
                        startActivity(i);
                    }
                } catch (Exception e) {

                    if (disclaimer == true) {
                        Intent i = new Intent(Splash.this, siteCheck.class);
                        startActivity(i);
                    } else {
                        Intent d = new Intent(Splash.this, Instruction.class);
                        startActivity(d);
                    }

                }
            }
    }, 1500);

答案 1 :(得分:0)

你不应该像这样使用线程。你可以使用它的处理程序。

new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {

                if (!firstRun) {
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putBoolean("firstRun", true);
                    editor.apply();
                    Intent i = new Intent(Splash.this, Instruction.class);
                    startActivity(i);
                    finish();


                } else {
                    try {
                        Bundle bundle = getIntent().getExtras();
                        a = bundle.getBoolean("key");

                        if (a == true) {
                            SharedPreferences.Editor editor = disc.edit();
                            editor.putBoolean("disclaimer", true);
                            editor.apply();

                            Intent i = new Intent(Splash.this, siteCheck.class);
                            startActivity(i);
                        }
                    } catch (Exception e) {

                        if (disclaimer == true) {
                            Intent i = new Intent(Splash.this, siteCheck.class);
                            startActivity(i);
                        } else {
                            Intent d = new Intent(Splash.this, Instruction.class);
                            startActivity(d);
                        }

                    }
                }
                finish();
            }
        }, 1500);
    }