在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有什么区别的更多相关文章

  1. [Android Pro] service中显示一个dialog 或者通过windowmanage显示view

    转载: http://blog.csdn.net/huxueyan521/article/details/8954844 通过windowmananger来在窗口上添加view的时候,需要设置aler ...

  2. service中显示一个dialog

    dialog是依附于activity存在的.但是app中经常需要使用以下的情况,在service中做一些后台操作,在某个临界条件满足时,显示一个dialog告知用户.这时dialog无法直接从serv ...

  3. .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter

    林德熙 小伙伴希望保存一个文件,并且希望如果出错了也要不断地重试.然而我认为如果一直错误则应该对外抛出异常让调用者知道为什么会一直错误. 这似乎是一个矛盾的要求.然而最终我想到了一个办法:让重试一直进 ...

  4. 题目一:编写一个类Computer,类中含有一个求n的阶乘的方法

    作业:编写一个类Computer,类中含有一个求n的阶乘的方法.将该类打包,并在另一包中的Java文件App.java中引入包,在主类中定义Computer类的对象,调用求n的阶乘的方法(n值由参数决 ...

  5. 【Azure 应用服务】Python flask 应用部署在Aure App Service中作为一个子项目时,解决遇见的404 Not Found问题

    问题描述 在成功的部署Python flask应用到App Service (Windows)后,如果需要把当前项目(如:hiflask)作为一个子项目(子站点),把web.config文件从wwwr ...

  6. Hibernate的多表查询,分装到一个新的实体类中的一个方法

    不知道是否还有其他方法实现,请高人指点. 如果涉及到多张表多字段查询,并且想利用查询出来的字段在界面层构建一个新的实体类,可以使用这种方法: 如果查询出来的多字段中,有多个字段的名字都相同(如想查询出 ...

  7. [转]Win7、Windows Server 2008下无法在Windows Service中打开一个已经存在的Excel 2007文件问题的解决方案

    昨天,组里一个小朋友告诉我,他写的报表生成服务中无法打开一个已经存在的Excel 2007文件,他的开发环境是Win7.Visual Studio .Net 2008(Windows Server 2 ...

  8. Python 判断一个字符串是否在列表中任何一个字符串中出现过

    strlist = ['a1', 'a2', 'b1'] if any("a" in s for s in strlist):

  9. 在windows service中启动类型“Automatic” 和 “Automatic (Delayed start)” 有何不同?

    问题: When installing Windows services there are two options for automatically starting a Windows serv ...

随机推荐

  1. ocp 1Z0-051 71-105题解析

    71. Which arithmeticoperations can be performed on a column by using a SQL function that is builtint ...

  2. MongoDB的备份与恢复

    0. 目录 整库备份 整库恢复 单collection备份 单collection恢复 1. 备份 MongoDB提供了备份工具,mongodump.exe,在bin目录下,其用法如下: mongod ...

  3. word2003公式编辑器公式显示不完整问题

    在段落里设置行距为:单倍行距.

  4. c++结束进程的程序

    //#include <winbase.h> #include <windows.h> #include <process.h> #include <Tlhe ...

  5. freemaker遍历嵌套list的map

    <#if disMap?exists> <#list disMap?keys as key> <#if ((disMap[key]))??&&((disM ...

  6. scons用户指南翻译(附gcc/g++参数详解)

    scons用户指南 翻译 http://blog.csdn.net/andyelvis/article/category/948141 官网文档 http://www.scons.org/docume ...

  7. Hadoop之父Doug Cutting

    生活中,可能所有人都间接用过他的作品,他是Lucene.Nutch .Hadoop等项目的发起人.是他,把高深莫测的搜索技术形成产品,贡献给普罗大众:还是他,打造了目前在云计算和大数据领域里如日中天的 ...

  8. 对PostgreSQL中tablespace 与 database, table的理解

    开始: 当前的tablesapce信息 pgsql=# select * from pg_tablespace; spcname | spcowner | spclocation | spcacl | ...

  9. C#-datagriview的表头高度的设置

  10. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...