【发布时间】:2019-02-27 04:10:15
【问题描述】:
我的应用程序中有一个浮动按钮服务(如 facebook messenger) 当点击时,我的活动从后台返回,但它不会以与缩小时相同的方式返回,它会再次调用 onCreate ,知道导致这种行为的原因吗?
在我的清单中,活动带有属性:
android:launchMode="singleTask"
它是由我的服务调用的:
Intent i = new Intent(FloatingViewService.this, DrawerActivity2.class);
i.putExtra("fromController",true);
i.setFlags(FLAG_FROM_BACKGROUND);
FloatingViewService.this.startActivity(i);
我的主要问题是在活动内部,我有一个 web 视图,每次单击按钮时它都会重新加载并调用活动,而不是保持不变。
更新后这是我在清单中的活动
<activity
android:name=".DrawerActivity2"
android:configChanges="orientation"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/OtherTheme"/>
更新 2
值得一提的是,它是一个位于应用程序中的库。
我试过这段代码来打开活动:
Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName()); startActivity(intent);
它打开了第一个(原始应用程序的)活动,而不是打开的活动。
我们将不胜感激任何帮助
【问题讨论】:
-
请发布您的清单。
-
什么时候添加 singleTask 作为启动模式?哪个方法被调用?创建?还是 onNewIntent?
-
好吧,我没有覆盖 onNewIntent 但每次都调用 onCreate
-
添加了有关问题的更多信息..
标签: android android-activity android-webview android-service