首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Screen加载MainActivity

Screen加载MainActivity
EN

Stack Overflow用户
提问于 2017-06-07 21:03:31
回答 3查看 4.5K关注 0票数 4

我目前有一个splashScreenActivity,它要求用户按下button上的按钮才能转到MainActivity

是否有可能加载MainActivity**'s 的所有内容而不将 UI显示在** splashScreenActivity**'s UI**之上,以便当他按下按钮时,他被重定向到MainActivity,并且所有数据都被100%加载?

提前感谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-06-08 20:25:52

我找到了我的问题的答案!

注意,在我的例子中,MainActivity 可以是任何活动

将Splash屏幕作为fragment而不是activity使您可以将MainActivityfragment覆盖,而MainActivity数据则加载在后台。

此时,无论何时准备就绪,只要将fragment的可见性设置为View.GONE或将其从片段堆栈getFragmentManager().popBackStack();中弹出,就会在加载了所有数据之后(永远不会离开)返回到MainActivity

票数 8
EN

Stack Overflow用户

发布于 2018-05-13 21:04:14

在主活动上使用可运行的全屏对话框

代码语言:javascript
运行
复制
public void showsplash() {

        final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.activity_splash_screen);
        dialog.setCancelable(true);
        dialog.show();

        final Handler handler  = new Handler();
        final Runnable runnable = new Runnable() {
            @Override
            public void run() {
                {
                    dialog.dismiss();
                }
            }
        };
        handler.postDelayed(runnable, 30000);
    }
票数 7
EN

Stack Overflow用户

发布于 2017-06-07 23:33:12

enter code here1)当用户在SplashScreenActivity中时,使用AsyncTask<>加载背景中的所有MainActivity内容。这将帮助您避免单击按钮将您从SplashScreenActivity转到MainActivity的额外步骤,这将通过意图的使用来处理。(参见下面的工作示例)

SplashScreenActivity.java

代码语言:javascript
运行
复制
        package foo.foo.load.mainactivity
        
        import android.app.Activity;
        import android.content.Context;
        import android.content.Intent;
        import android.content.pm.ActivityInfo;
        import android.content.res.AssetManager;
        import android.content.res.Configuration;
        import android.os.AsyncTask;
        import android.os.Bundle;
        import android.util.Log;
        import java.util.ArrayList;
        import java.util.List;
        
        public class SplashScreenActivity extends Activity {
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_splash);      
        
                // Make call to execute AsycTasks<> here
                // This helps avoid the extra step of clicking on a button
                // to take you to the MainActivity
                new StartMainActivity().execute(this);
        
                Thread timerThread = new Thread() {
                    public void run() {
                        try {
                            sleep(2000);
                        } catch(InterruptedException e) {
                            e.printStackTrace();
                        } finally {
                            // After 2 seconds the Splashscreen will disappear and user is taken to MainActivity
                            Intent splashScreenIntent = new Intent(SplashScreenActivity.this, MainActivity.class);
                            startActivity(splashScreenIntent);
                        }
                    }
                };
        
                timerThread.start();
            }
        
            @Override
            protected void onPause() {
                super.onPause();
                finish();
            }
        
            private class StartMainActivity extends AsyncTask<Context, Void, Intent> {
        
                Context ctx;
        
                @Override
                protected Intent doInBackground(Context... params) {
                    ctx = params[0];
                    AssetManager assetManager = ctx.getAssets();
                    final CBLite cblite = new CBLite(new AndroidContext(ctx), assetManager);
                    
                    // Handle all your MainActivity Contents call here 
                    // Begin MainActivity Content Calls            
                    Image.getImages();
                    Navigation.getMainNavigation();
                    // End MainActivity Content Calls
            
                    Intent in = new Intent();
                    in.setClass(ctx, MainActivity.class);
        
                    return in;
                }
        
                @Override
                protected void onPostExecute(Intent intent) {
                    ctx.startActivity(intent);
                    super.onPostExecute(intent);
                }
        
            }
        }

activity_splash.xml

代码语言:javascript
运行
复制
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:background="@drawable/splashscreen_background_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:id="@+id/splashScreenMainTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="150dp"
            android:gravity="center"
            android:text="Header Title"
            android:visibility="visible"/>
    
        <TextView
            android:id="@+id/splashScreenSubTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/splashScreenMainTitle"
            android:layout_marginBottom="40dp"
            android:gravity="center"
            android:text="Sub Header Title"
            android:visibility="visible"/>
    
        <ImageView
            android:id="@+id/splashScreenLogo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/splashScreenSubTitle"
            android:src="@drawable/logo"
            android:layout_gravity="center_horizontal"
            android:background="@android:color/transparent"/>
    
    </RelativeLayout>

activity_main.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_menu_search" />    
   </android.support.design.widget.CoordinatorLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44422725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档