初始屏幕仅在全新安装后显示

发布于 2024-11-07 03:31:58 字数 2591 浏览 0 评论 0原文

我用一个 Activity 制作了一个闪屏。我遵循以下示例 http://www.anddev.org/viewtopic.php?t=815 安装后效果很好。但这就是我的问题开始的地方。它仅在安装后显示。因此,当我终止我的应用程序时,不再加载该活动,而是直接加载我的第二个活动。我认为这有点奇怪,因为我在启动屏幕上的清单文件中设置了意图过滤器。

有人知道如何解决这个问题吗?

这是我的清单文件:

<application android:icon="@drawable/icon" android:label="@string/app_name" 
android:theme="@style/MyLightTheme.NoShadow" android:debuggable="true"  android:name="android.app.Application" > 
<uses-library android:name="com.google.android.maps" />

    <activity android:name=".MainActivity" android:label="@string/app_name"></activity>
    <activity android:name="FindJob" android:label="@string/FindJobTitel"></activity>
    <activity android:name="JobDetails" android:label="@string/MaatTitel" ></activity>
    .
    .
    .
    <activity android:name="Splash" android:configChanges="orientation" android:label="@string/Splash">    
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter></activity>
</application>

Splashscreencode:

private final int SPLASH_DISPLAY_LENGHT = 5000;
//private Drawable drawable;
private ProgressBar mProgress;
private int mProgressStatus = 0;


/** Called when the activity is first created. */ 
@Override
public void onCreate(Bundle icicle) {
     super.onCreate(icicle);          
     setContentView(R.layout.splash);         
     mProgress = (ProgressBar) findViewById(R.id.progressBar1);         
     }


public void onStart(){
    super.onStart();
    //Log.i("START", "In on start");
    Thread splashThread = new Thread() {
        @Override
        public void run() {
           try {
              int waited = 0;
              while (mProgressStatus < 100) {
                 sleep(80);
                 //waited += 200;
                 mProgressStatus += 4;
                 mProgress.setProgress(mProgressStatus);
              }
           } catch (InterruptedException e) {
              // do nothing
           } finally {
              finish();
             Intent i = new Intent(Splash.this, MainActivity.class);
              startActivity(i);
           }
        }
     };
     splashThread.start();   
}

更新:将 android:noHistory="true" 放在 ManifestFile 的 mainActivity 中可以解决问题。然而。每次我离开应用程序时,它都会重新启动所有应用程序(启动画面、主活动,而不是最后加载的活动)。但比以前好多了。

I have made a splash screen with an Activity. I followed following example http://www.anddev.org/viewtopic.php?t=815 and it works perfectly when installed. But that's where my problem starts. It only shows after an install. So When I kill my app, the Activity isn't loaded anymore, it directly loads my second Activity. I think it's a little weird, because I set the intent-filter in my manifestfile on the splash screen.

Anyone knows how to solve this problem?

This is my manifestfile:

<application android:icon="@drawable/icon" android:label="@string/app_name" 
android:theme="@style/MyLightTheme.NoShadow" android:debuggable="true"  android:name="android.app.Application" > 
<uses-library android:name="com.google.android.maps" />

    <activity android:name=".MainActivity" android:label="@string/app_name"></activity>
    <activity android:name="FindJob" android:label="@string/FindJobTitel"></activity>
    <activity android:name="JobDetails" android:label="@string/MaatTitel" ></activity>
    .
    .
    .
    <activity android:name="Splash" android:configChanges="orientation" android:label="@string/Splash">    
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter></activity>
</application>

Splashscreencode:

private final int SPLASH_DISPLAY_LENGHT = 5000;
//private Drawable drawable;
private ProgressBar mProgress;
private int mProgressStatus = 0;


/** Called when the activity is first created. */ 
@Override
public void onCreate(Bundle icicle) {
     super.onCreate(icicle);          
     setContentView(R.layout.splash);         
     mProgress = (ProgressBar) findViewById(R.id.progressBar1);         
     }


public void onStart(){
    super.onStart();
    //Log.i("START", "In on start");
    Thread splashThread = new Thread() {
        @Override
        public void run() {
           try {
              int waited = 0;
              while (mProgressStatus < 100) {
                 sleep(80);
                 //waited += 200;
                 mProgressStatus += 4;
                 mProgress.setProgress(mProgressStatus);
              }
           } catch (InterruptedException e) {
              // do nothing
           } finally {
              finish();
             Intent i = new Intent(Splash.this, MainActivity.class);
              startActivity(i);
           }
        }
     };
     splashThread.start();   
}

UPDATE: placing android:noHistory="true" in the mainActivity in ManifestFile solves the problem. HOWEVER. Each time I leave the app, it restarts all of it (splash screen, mainactivity and not last activity loaded). But it's better then before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文