java - 从“启动屏幕”活动转换在回调中不起作用
问题描述
我目前正在开发一个带有“启动屏幕活动”的 Android 应用程序。在启动屏幕活动onCreate
方法中,我使用此方法从缓存中异步加载数据:
void NewslistViewModel.fetchFromCache(Runnable onFinished)
现在我想在缓存加载过程完成后使用onFinished
回调导航到下一个:Activity
public class SplashScreenActivity extends DaggerAppCompatActivity {
@Inject
ViewModelProviderFactory _providerFactory;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// the real code decides to which Activity to go next here
// ...
Intent intent = new Intent(this, MainActivity.class);
NewsListViewModel newsListViewModel =
new ViewModelProvider(this, _providerFactory).get(NewsListViewModel.class);
newsListViewModel.fetchFromCache(
() -> {
Intent[] intents = TaskStackBuilder.create(this)
.addNextIntentWithParentStack(intent)
.getIntents();
if (intents.length > 0) {
intents[0].setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
runOnUiThread(() -> {
SplashScreenActivity.this.startActivities(intents, ActivityOptions.makeSceneTransitionAnimation(SplashScreenActivity.this).toBundle());
});
});
}
}
我在这里遇到的问题是,现在启动画面并没有自行完成。在我物理触摸设备上的屏幕后,设备的反应就好像它已经在里面一样MainActivity
,所以这似乎只是一个显示问题(?)。
我打电话的原因ActivityOptions.makeSceneTransitionAnimation
是因为没有它我有丑陋的灰色过渡(如本问题所述)。另外,我需要打电话addNextIntentWithParentStack
,因为我的应用程序可以通过单击通知来打开,这会引导启动屏幕活动导航到主要活动的子活动。
我的初始屏幕活动定义如下:
AndroidManifest.xml:
<activity android:name=".SplashScreenActivity"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
样式.xml:
<style name="Theme.AppCompat.DayNight.NoActionBar.Launcher">
<item name="android:windowBackground">@drawable/splash_screen_background</item>
</style>
splash_screen_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- The android:opacity=”opaque” line — this is critical in preventing a flash of black as your theme transitions. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@android:color/white"/>
<item
android:width="146dp"
android:height="201dp"
android:drawable="@drawable/splash_full_512"
android:gravity="center" />
</layer-list>
我很确定我在这里做了一些根本错误的事情,所以非常感谢任何帮助。
解决方案
推荐阅读
- javascript - React,如何按列而不是按行构造表
- reactjs - React useReducer:收到有效负载,状态未更新
- javascript - 在 react 中加载后获取 Suspense 元素的高度(尺寸)
- node.js - gulp-4 将多个 js 文件合并为一个:错误标识符已被定义
- objective-c - 从可可应用程序运行applescript停止工作
- flutter - 用于检查 Dart/Flutter 代码(如 Codebeat 或 Codacy)的服务?
- javascript - 部署到生产环境时出现 ELIFECYCLE 错误 1
- pandas - 尝试减去列均值并除以数据框中每列的列标准差时,df.apply() 的 AttributeError
- java - 通过 docker-compose.yaml 运行 Acrarium 会导致 HikariPool-1 - 池初始化期间出现异常
- d3.js - 如何修复“react-d3-tree”?