`

Calling startActivity() from outside of an Activity context requires the FLAG_A

 
阅读更多
10-21 01:05:37.121: I/TestRunner(1224): ----- begin exception -----
10-21 01:05:37.131: I/TestRunner(1224): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
10-21 01:05:37.131: I/TestRunner(1224): 	at android.app.ContextImpl.startActivity(ContextImpl.java:847)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
10-21 01:05:37.131: I/TestRunner(1224): 	at com.hello.jifenshenqi.common.Utils.startApp(Utils.java:55)
10-21 01:05:37.131: I/TestRunner(1224): 	at com.hello.jifenshenqi.test.DemoTest.test_1_taobao(DemoTest.java:50)
10-21 01:05:37.131: I/TestRunner(1224): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-21 01:05:37.131: I/TestRunner(1224): 	at java.lang.reflect.Method.invoke(Method.java:511)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
10-21 01:05:37.131: I/TestRunner(1224): 	at junit.framework.TestCase.runBare(TestCase.java:127)
10-21 01:05:37.131: I/TestRunner(1224): 	at junit.framework.TestResult$1.protect(TestResult.java:106)
10-21 01:05:37.131: I/TestRunner(1224): 	at junit.framework.TestResult.runProtected(TestResult.java:124)
10-21 01:05:37.131: I/TestRunner(1224): 	at junit.framework.TestResult.run(TestResult.java:109)
10-21 01:05:37.131: I/TestRunner(1224): 	at junit.framework.TestCase.run(TestCase.java:118)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:537)
10-21 01:05:37.131: I/TestRunner(1224): 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
10-21 01:05:37.131: I/TestRunner(1224): ----- end exception -----

 

原因分析:

Context中有一个startActivity方法,Activity继承自Context,重载了startActivity方法。如果使用 Activity的startActivity方法,不会有任何限制,而如果使用Context的startActivity方法的话,就需要开启一个新的task,遇到上面那个异常的,都是因为使用了Context的startActivity方法。解决办法是,加一个flag。intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

 

解决办法:

Intent intent = new Intent();
intent.setClass(mContext, PhotoView.class);
Bundle bundle = new Bundle();
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
mContext.startActivity(intent);

 

分享到:
评论

相关推荐

    安卓中出现过的一些容易被忽略的异常整理

    W/System.err: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? W/System.err: at...

    mmu_context.rar_The Calling

    本文将深入探讨"mmu_context.rar_The Calling"所涉及的知识点,包括MMU上下文的概念、作用以及在Linux内核中的实现。 1. **MMU上下文**:MMU上下文是一个抽象概念,代表了一个进程或系统中的内存布局状态。每个进程...

    数位板压力测试

    The design presented here is based on the input of numerous professionals from the pointing device manufacturing and Windows soft¬ware development industries. In this document, the words "tablet" ...

    Java邮件开发Fundamentals of the JavaMail API

    In the context of the JavaMail API, your JavaMail-based program will communicate with your company or Internet Service Provider's (ISP's) SMTP server. That SMTP server will relay the message on to ...

    微软内部资料-SQL性能优化2

    To run outside the calling processes address space. OLEDB providers can run in-process or out of process. When running out of process, they run under the context of DLLHOST.EXE. Memory Leak To reserve...

    Jess__The_Java_Expert_System_Shell

    Jess__The_Java_Expert_System_Shell:DistributionCategory UC-411 SAND98-8206 (revised)Unlimited... A guide to calling Java functions from Jess, and to extending Jess by writing Java code, is alsoincluded.

    微软内部资料-SQL性能优化3

    An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the ...

    Calling_R_from_python_use_Rpy2_Windows_rpy2.zip

    Calling_R_from_python_use_Rpy2_Windows_rpy2

    2009 达内Unix学习笔记

    [] 匹配中括号里的内容[a-z][A-Z][0-9]。 ! 事件。 $ 取环境变量的值。 | 管道。把前一命令的输出作为后一命令的输入,把几个命令连接起来。 |经常跟tee连用,tee 把内容保存到文档并显示出来。 三、通用后...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The definition of an inline function needs to be in a header file, so that the compiler has the definition available for inlining at the call sites. However, implementation code properly belongs in ....

    SAP FRC接口调用calling RFC_METADATA_GET -- see log for details报错解决方案

    SAP.Middleware.Connector.RfcCommunicationException:“destination XXXX failed when calling RFC_METADATA_GET -- see log for details” 猜测的原因: 老的DLL库在获取接口实例时,会触发“RFC_METADATA_GET”...

    Calling-Comis.rar_The Dos_trnsys_trnsys matlab

    TRNSYS is a complete and extensible software environment for the transient ... interactive calls during the simulation (e.g. Microsoft Excel, Matlab, COMIS, etc.).

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object....

    IBO v5.3.3 Build 1955(January 2, 2014) Full Source

    I fixed a bug where a dataset could be put out of search mode by the TIB_Grid calling ValidateRows and causing the dataset to open when it wasn't being expected to. I fixed a bug in the handling of a...

    The Art of Assembly Language Programming

    Some Final Comments on the MOV Instructions <br>4.9 Laboratory ...A Quick Look at CodeView 4.9.5.2 The Source Window 4.9.5.3 The Memory Window 4.9.5.4 The Register Window 4.9.5.5 The ...

    Calling C from IDL(2002)

    《Calling C from IDL》是2002年发布的一份文档,主要探讨了如何在IDL(Interactive Data Language)环境中调用C和C++代码。IDL是一种强大的数据处理和可视化语言,广泛应用于科学计算和数据分析领域。而C和C++是...

    英文原版-The Intelligent Enterprise in the Era of Big Data 1st Edition

     … the enterprise of today has changed … wherever you sit in this new corporation … Srinivasan gives us a practical and provocative guide for rethinking our business process … calling us all to ...

Global site tag (gtag.js) - Google Analytics