初始屏幕仅在全新安装后显示
我用一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论