第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么每次更改啟動屏幕時我的應用程序都會從??后臺打開?

為什么每次更改啟動屏幕時我的應用程序都會從??后臺打開?

白衣非少年 2023-06-21 13:30:46
我創(chuàng)建了一個包含 3 個啟動畫面的應用程序。它們在 10 秒后出現并消失,下一個取代它,直到第三個結束,然后主活動打開,應用程序正常運行。問題是,如果用戶在任何這些啟動屏幕期間將應用程序發(fā)送到后臺,則 10 秒后,即使用戶正在使用另一個應用程序,應用程序也會回到前臺并顯示下一個啟動屏幕或主要活動。我查看了代碼,似乎找不到任何可以解釋這一點的內容。在 Android Studio 更新到 3.5 之前它工作正常,我不知道為什么會導致這個問題。public class  loadScreen extends AppCompatActivity {private int SLEEP_TIMER = 3;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    requestWindowFeature(Window.FEATURE_NO_TITLE);    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                            WindowManager.LayoutParams.FLAG_FULLSCREEN);    setContentView(R.layout.activity_load_screen);    LogoLauncher logoLauncher = new LogoLauncher();    logoLauncher.start();}private class  LogoLauncher extends Thread{    public void run(){        try{            sleep(3000 * SLEEP_TIMER);        }catch(InterruptedException e)        {            e.printStackTrace();        }        Intent intent = new Intent(loadScreen.this, createdby.class);        startActivity(intent);        loadScreen.this.finish();    }}@Overridepublic void onBackPressed() {}}我希望如果應用程序在啟動畫面序列期間在用戶返回時被發(fā)送到后臺,它將從他們離開的地方恢復。
查看完整描述

2 回答

?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

您的問題是即使您的應用程序在后臺,也會調用 startActivity。這將在調用時打開您的應用程序。因此,您需要在該部分中創(chuàng)建一些邏輯來檢查是否允許調用 startActivity 方法。


編輯:用于檢查活動的待啟動的代碼。試試這個!


private static final String PENDING_LAUNCH_KEY = "PENDING_LAUNCH";

private boolean pendingLaunch;

private boolean activityPaused;


@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);


    if (savedInstanceState != null) {

        pendingLaunch = savedInstanceState.getBoolean(PENDING_LAUNCH_KEY);

    }


    requestWindowFeature(Window.FEATURE_NO_TITLE);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

                        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_load_screen);


    if (!pendingLaunch) {

        LogoLauncher logoLauncher = new LogoLauncher();

        logoLauncher.start();

    }

}


@Override

protected void onResume() {

    activityPaused = false; 


    if (pendingLaunch) {

        pendingLaunch = false;

        startAndFinish();

    }

}


@Override

protected void onPause() {

    activityPaused = true;

}


@Override

public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {

    outState.putBoolean(PENDING_LAUNCH_KEY, pendingLaunch);

    super.onSaveInstanceState(outState, outPersistentState);

}


private class  LogoLauncher extends Thread{

    public void run(){

        try{

            sleep(3000 * SLEEP_TIMER);

        }catch(InterruptedException e)

        {

            e.printStackTrace();

        }

        if (activityPaused) pendingLaunch = true;

        else startAndFinish();

    }

}


private void startAndFinish() {

    Intent intent = new Intent(loadScreen.this, createdby.class);

    startActivity(intent);

    finish();

}


查看完整回答
反對 回復 2023-06-21
?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

即使用戶正在使用另一個應用程序,該應用程序也會將自己帶回前臺

即使您的應用程序進入后臺,您的線程仍在運行!解決方案是,您必須在方法中使用terminate該線程onPause

它將從他們離開的地方恢復。

飛濺活動

public class SplashActivity extends AppCompatActivity {


private Handler handler = null;

private long SPLASH_TIMEOUT = 5000;


@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_splash);

    handler = new Handler();

}


private Runnable splashRunnable = new Runnable() {

    @Override

    public void run() {

        Intent mySuperIntent = new Intent(SplashActivity.this, SplashActivity1.class);

        startActivity(mySuperIntent);

        finish();

    }

};


@Override

protected void onPause() {

    super.onPause();

    handler.removeCallbacks(splashRunnable);

}


@Override

protected void onResume() {

    super.onResume();

    handler.postDelayed(splashRunnable, SPLASH_TIMEOUT);


}

}

SplashActivity1與SplashActivity 相同的代碼只會intent發(fā)生變化。


import android.content.Intent;

import android.os.Handler;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;


public class SplashActivity1 extends AppCompatActivity {


private Handler handler = null;

private long SPLASH_TIMEOUT = 5000;


@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_splash1);

    handler = new Handler();

}


private Runnable splashRunnable = new Runnable() {

    @Override

    public void run() {

        Intent mySuperIntent = new Intent(SplashActivity1.this, 

MainActivity.class);

        startActivity(mySuperIntent);

        finish();

    }

};


@Override

protected void onPause() {

    super.onPause();

    handler.removeCallbacks(splashRunnable);

}


@Override

protected void onResume() {

    super.onResume();

    handler.postDelayed(splashRunnable, SPLASH_TIMEOUT);


}

}


查看完整回答
反對 回復 2023-06-21
  • 2 回答
  • 0 關注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號