- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题是... 如果我们尝试在 startActivity() 之后执行一些代码,我们会在调用当前 Activity 的 onPause() 之前完全执行吗?也就是说,我不会知道当包含它的方法到达末尾时是否真的会调用 startActivity()(finish()
方法发生的事情)。
我有一个示例,其中我想在基于某些条件启动新 Activity 后 detach()
一个对象(具有数据库连接),但我需要此对象来评估一个健康)状况。我知道我可以检查该条件并存储 bool 值和 detach()
它在第一个 if
之前,但我想知道以下代码是否“合法” .
谢谢!
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
School selectedSchool = new School((Cursor)l.getItemAtPosition(position));
mSharedPreferences.edit()
.putLong(DatabaseManager.SCHOOL_ID, selectedSchool.getIdOpenErp())
.commit();
School.SchoolManager schoolManager = new School.SchoolManager(this);
Long[] sessionIdsOpenErpOfSelectedSchool = schoolManager.getSessionIdsOpenErp(selectedSchool);
if (sessionIdsOpenErpOfSelectedSchool.length > 0) {
if (schoolManager.isPreviousWorkingSchoolPresent()) { // line 10
Intent iParticipationManagement = new Intent(this, ParticipationManagement.class);
startActivity(iParticipationManagement);
} else {
Intent iSelectExistingSession = new Intent(this, SelectExistingSession.class);
startActivity(iSelectExistingSession);
}
} else {
Intent iSelectNewSession = new Intent(this, SelectNewSession.class);
startActivity(iSelectNewSession);
}
// The following line will be executed after one of the startActivity() methods is called...
// Is this legal? Or should I get the value from isPreviousWorkingSchoolPresent() (at line 10)
// before the first if and do the detach() there as well?
schoolManager.detach();
}
最佳答案
任何你想在调用 startActivity()
的方法中执行的操作都会在 你收到对 onPause()
的调用之前执行.问题是,您的应用程序默认使用一个主线程,调用 onPause()
和其他生命周期方法发生在它上面。因此,当此线程忙于执行您的方法中的代码时,它无法处理任何其他内容。
如果您的方法在其他线程中执行,这只会是一个问题。然而,情况并非如此,因为此方法用于监听 UI 事件,所以我假设它总是从主线程调用。
关于android - 我们可以在暂停之前在 startActivity() 之后执行代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9619303/
我几天前开始进行android开发。我实现了一个 recylerview,在 recyclerview 适配器的 OnBindViewHolder 方法中,我在 recyclerview 项目上使用了
我已阅读文章https://github.com/Kotlin/anko/wiki/Anko-Commons-%E2%80%93-Intents . 我可以使用 startActivity(inten
我的 BroadcastReceiver 的 onReceive 函数中有以下代码。 public void onReceive(Context context, Intent intent) {
无论我做什么,我都无法开始新 Activity 。我重新下载了所有的Android SDK。我重新下载了Eclipse并再次安装了ADT插件 错误日志 09-16 17:53:51.537: W/II
我有以下 Activity ,当调用 startactivity() 时,应用程序被强制关闭,我已经搜索了几天失败的原因,有人可以帮助我吗? 应用程序: package com.example.dec
我是 Android 开发新手,在创建新 Activity 时遇到问题。 我想在开始之前使用我的 Activity 。例如,我已经尝试过: MyActivity menu = new MyActivi
在我的应用程序菜单类中,我想要一个按钮来启动 Activity 。这不适用于 StartActivity() 方法,因为它根本不是 Activity 的子类。那我该怎么办呢? 如果你读过《Beginn
我对 Android/Java 完全陌生。我正在尝试创建一个应用程序来连接到我的 TCP 服务器以从 mySQL 获取数据。 我有以下内容:MainActivity - 这是登录屏幕。输入用户名和密码
我刚刚开始 Android 开发,我被这段代码困住了: public class Home extends Activity { /** Called when the activity is
我有一个对话框提示用户确认删除。 在用户点击删除后弹出一个简单的警告。我需要重定向到一个新 Activity ,但在我有机会在确认警报上单击“确定”之前,startActivity 已触发。我在它搞砸
为什么要在服务中使用 startActivity()?如果我需要一个 Activity 必须调用一个 Activity ,如果我需要一个“延迟 Activity ”我必须使用通知。那么,我为什么要使用
引擎盖下发生了什么?这会以某种方式传递给操作系统,并且表明操作系统会找到正确的 Activity/Activity 并启动它?是否有在 Android 中运行的服务/库来处理这个?我正在尝试修改操作系
我有一个主类和一个单独的类 (OnClickBtn.java),我只想在其中保留按钮方法。我不想从主类而是从 OnClickBtn.java 开始新的 Activity 。 我已经运行了该程序,但它在
我正在学习 android 开发。这只是示例项目。所以我在按钮点击事件上创建了相同的 Activity (见代码)。在第一个 Activity 之后,我可以看到带有“qwerty”文本的新 Activ
我已经设置了一个从菜单按钮执行的 Activity 。 Activity 启动并短暂出现然后崩溃。我已将附加 Activity 添加到 list 文件。代码如下。我最近从 Eclipse 切换到 An
我试图从 OptionsMenu 启动一个 Activity ,但它没有启动。为什么? @Override public boolean onOptionsItemSelected(MenuItem
我创建了一个 activity( Activity 编号 1),其中包含 2 个 Views、一个 button 和一个 textView这两个 View 被共享到另一个activity(activi
截至今天上午,我已经尝试整合足够的知识来制作一个非常基本的应用程序来演示一个概念。这个想法是显示谷歌地图,用户按下他们想要添加标记的位置,然后弹出一个屏幕,他们可以在其中填写更多信息,然后当有人点击该
我正在制作一个绘图应用程序并想分享图像。但是,我遇到了 startActivity 部分的错误,其中错误写道 The method startActivity(Intent) is undefined
调用 startActivity 时,我一直收到 NPE,我认为这与我提供给 Intent 的上下文有关。当我从 Internet 获取 xml 数据时,我试图让启动画面保持不变。 splash Ac
我是一名优秀的程序员,十分优秀!