【安卓面试题】在一个Activity启动另一个Activity和在Service中启动一个Activity有什么区别
在Activity中可以直接使用Intent启动另一个Activity
显式Intent intent = new Intent(context, activity.class)
隐式 Intent intent = new Intent(“com.aa.www.act”);
startActivity(intent);
如果从Service中用同样方法启动Activity 的话,会报错:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAGACTIVITYNEWTASK flag. Is this really what you want?
需要设置 intent.setFlags(Intent.FLAGACTIVITYNEWTASK); 再开启activity 代码如下 :
Intent intent = new Intent("hahaha.hahaha");
intent.setFlags(Intent.FLAGACTIVITYNEW_TASK);
startActivity(intent);
【安卓面试题】在一个Activity启动另一个Activity和在Service中启动一个Activity有什么区别的更多相关文章
- [Android Pro] service中显示一个dialog 或者通过windowmanage显示view
转载: http://blog.csdn.net/huxueyan521/article/details/8954844 通过windowmananger来在窗口上添加view的时候,需要设置aler ...
- service中显示一个dialog
dialog是依附于activity存在的.但是app中经常需要使用以下的情况,在service中做一些后台操作,在某个临界条件满足时,显示一个dialog告知用户.这时dialog无法直接从serv ...
- .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter
林德熙 小伙伴希望保存一个文件,并且希望如果出错了也要不断地重试.然而我认为如果一直错误则应该对外抛出异常让调用者知道为什么会一直错误. 这似乎是一个矛盾的要求.然而最终我想到了一个办法:让重试一直进 ...
- 题目一:编写一个类Computer,类中含有一个求n的阶乘的方法
作业:编写一个类Computer,类中含有一个求n的阶乘的方法.将该类打包,并在另一包中的Java文件App.java中引入包,在主类中定义Computer类的对象,调用求n的阶乘的方法(n值由参数决 ...
- 【Azure 应用服务】Python flask 应用部署在Aure App Service中作为一个子项目时,解决遇见的404 Not Found问题
问题描述 在成功的部署Python flask应用到App Service (Windows)后,如果需要把当前项目(如:hiflask)作为一个子项目(子站点),把web.config文件从wwwr ...
- Hibernate的多表查询,分装到一个新的实体类中的一个方法
不知道是否还有其他方法实现,请高人指点. 如果涉及到多张表多字段查询,并且想利用查询出来的字段在界面层构建一个新的实体类,可以使用这种方法: 如果查询出来的多字段中,有多个字段的名字都相同(如想查询出 ...
- [转]Win7、Windows Server 2008下无法在Windows Service中打开一个已经存在的Excel 2007文件问题的解决方案
昨天,组里一个小朋友告诉我,他写的报表生成服务中无法打开一个已经存在的Excel 2007文件,他的开发环境是Win7.Visual Studio .Net 2008(Windows Server 2 ...
- Python 判断一个字符串是否在列表中任何一个字符串中出现过
strlist = ['a1', 'a2', 'b1'] if any("a" in s for s in strlist):
- 在windows service中启动类型“Automatic” 和 “Automatic (Delayed start)” 有何不同?
问题: When installing Windows services there are two options for automatically starting a Windows serv ...
随机推荐
- Hadoop学习之--Capaycity Scheduler配置参数说明
以下列举出来的是capacity关于queue和user资源使用量相关的参数说明: mapred.capacity-scheduler.queue.xxx.capacity: 队列的资源容量百分比,所 ...
- Base64编解码(C++版)
#include <string> using namespace std; class ZBase64 { public: /*编码 DataByte [ ...
- Struts2 文件上传
一:表单准备 ① 要想使用HTML 表单上传一个或多个文件 –须把 HTML表单的 enctype属性设置为multipart/form-data –须把HTML 表单的method ...
- BAT-使用BAT生成快捷方式
@( echo [InternetShortcut] echo URL=C:\Windows\System32\calc.exe echo IconIndex=0 echo IconFile=C:\W ...
- bat定时执行,清除PHP缓存
bat中需要设置一个等待时间,执行完一条命令后,等待30分钟后在执行第二条命令,请问怎么做?急急急----谢谢大家 @echo off& echo wscript.sleep wscript. ...
- iOS UIWebView加载时添加进度条
标注:此框架仅适合UIWebView 对iOS8后新出的WKWebView不适用,当然,你可以尝试修改框架里的几个代理方法. 框架是:NJKWebViewProgress 导入头文件 #import ...
- 2015 NOIP day1 t1 神奇的幻方 模拟
神奇的幻方 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.luogu.org/problem/show?pid=2615 Descri ...
- 套题 Codeforces Round #277 (Div. 2)
A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- delphi Sender和Tag的用法
var Form1: TForm1; SelectedColor:TColor;//clBlack; //Defaultimplementation{$R *.dfm}procedure TFor ...