Java Android Splash活动

Java Android Splash活动,java,android-activity,splash-screen,android-bluetooth,Java,Android Activity,Splash Screen,Android Bluetooth,我有一个关于Flash的问题,我如何请求用户启用蓝牙,等待它,然后在用户允许的情况下继续启动主要活动,或者如果用户拒绝,则退出应用程序,我的应用程序中有以下代码 // Library from Android import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.content.Intent; import android.os.Bundle; import android.u

我有一个关于Flash的问题,我如何请求用户启用蓝牙,等待它,然后在用户允许的情况下继续启动主要活动,或者如果用户拒绝,则退出应用程序,我的应用程序中有以下代码

// Library from Android
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.Toast;

// User defined library
import java.io.IOException;

import eu.atriaparis.support.ATRIAExceptions.BluetoothDeviceException;
import eu.atriaparis.support.R;
import eu.atriaparis.ledplayfinal.MainControllerActivity;


// Starting Splash Activity for loading other background process. before main.
// Edited Harsha S, for ATRIA Paris - 2015
public class SplashActivity extends Activity {

    private static String TAG = SplashActivity.class.getName();
    private static long SLEEP_TIME = 3;                         //Max Loading Time
    private final static int REQUEST_ENABLE_BT = 22;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Removes notification bar

        setContentView(R.layout.activity_splash);

        // Start timer and launch main activity
        IntentLauncher launcher = new IntentLauncher();
        launcher.start();

        // Wait for the launcher thread to complete.

    }

//    @Override
//    public void onActivityResult(int requestCode, int resultCode, Intent data) {
//        Log.d(TAG,"onActivityResult");
//        switch (requestCode) {
//            case REQUEST_ENABLE_BT:
//                if (resultCode == Activity.RESULT_CANCELED) {
//                    // User did not enable Bluetooth or an error occurred
//                    finish();
//                }
//                break;
//            default:
//                super.onActivityResult(requestCode, resultCode, data);
//                break;
//        }
//    }

    // Internal Class which loads all the other background activity and then starts main thread.
    // ATRIA Paris - 2015
    private class IntentLauncher extends Thread {

        private ProgressBar progressBar;
        private int progressStatus = 0;

        @Override
        /**
         * Sleep for some time and than start new activity.
         */
        public void run() {

            // Progress
            progressBar = (ProgressBar) findViewById(R.id.progressBar1);

            // Network
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

            // For Error Handling
            BluetoothDeviceException exception;


            try {

                // Status 1, Check device and bluetooth status
                Thread.sleep(SLEEP_TIME*1000/3);
                progressStatus = 20;
                progressBar.setProgress(progressStatus);

                // Status 2, Check Network Status
                if (mBluetoothAdapter == null) {
                    Toast.makeText(getBaseContext(), getResources().getString(R.string.BluetoothAdapterNotFound), Toast.LENGTH_SHORT).show();
                    Thread.sleep(SLEEP_TIME*1000/3);
                    throw new BluetoothDeviceException("Bluetooth Module Not Found");
                }
                if (!mBluetoothAdapter.isEnabled()) {
                    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
                    Thread.sleep(SLEEP_TIME*1000/3);
                    Log.d("Splash", "Bluetooth Status + "+ mBluetoothAdapter.isEnabled());
                }
                progressStatus = 50;
                progressBar.setProgress(progressStatus);

                // Status 3
                Thread.sleep(SLEEP_TIME*1000/3);
                progressStatus = 75;
                progressBar.setProgress(progressStatus);

                // Final Activity
                // Load background activities
                Thread.sleep(SLEEP_TIME*1000/3);
                progressStatus = 100;
                progressBar.setProgress(progressStatus);

                // Start main activity
                Intent intent = new Intent(SplashActivity.this, MainControllerActivity.class);
                SplashActivity.this.startActivity(intent);
                SplashActivity.this.finish();

            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }
        }
    }


}

看代码,这很正常,你总是在主要活动中着陆。没有任何逻辑可以阻止这一点。 代码行

//启动主要活动 Intent Intent=新IntentSplashActivity.this,MainControllerActivity.class; SplashActivity.this.startActivityintent; 这个完成


是的,总是执行。您需要处理意外的行为,并采取适当的措施,无论这是什么。

您所说的Flash是什么意思?就像加载屏幕或启动屏幕一样,您能更具体地回答您的问题吗?你尝试过什么,什么不起作用?在大多数现代应用程序中,当他们开始加载Screenship活动时,我在这个项目上工作了一段时间,但当用户启动我们的应用程序时,他在Screenship加载屏幕上着陆,然后我们在后台完成一些事情,然后进入主要活动,我不知道如何控制此操作,我可以在此应用程序转到主活动后启动“活动启动加载”活动,即使加载有问题。例如,在上述活动中,我有一些背景信息,如检查网络、蓝牙等,这是我们的应用程序所需的,如果用户未启用此选项,则应用程序应在启动/放置活动时停止,但不会降落到主活动。