<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>android.util.AndroidRuntimeException &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/android-util-androidruntimeexception/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Wed, 04 Dec 2019 01:00:28 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>android.util.AndroidRuntimeException &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>targetSdkVersion 設定成 API 28 之後噴出的兩個 RuntimeException 處理</title>
		<link>https://noter.tw/6507/%e5%8d%87%e7%b4%9a-api-28-%e4%b9%8b%e5%be%8c%e5%99%b4%e5%87%ba%e7%9a%84%e5%85%a9%e5%80%8b-runtimeexception-%e8%99%95%e7%90%86/</link>
					<comments>https://noter.tw/6507/%e5%8d%87%e7%b4%9a-api-28-%e4%b9%8b%e5%be%8c%e5%99%b4%e5%87%ba%e7%9a%84%e5%85%a9%e5%80%8b-runtimeexception-%e8%99%95%e7%90%86/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sat, 16 Nov 2019 13:42:22 +0000</pubDate>
				<category><![CDATA[手機 App]]></category>
		<category><![CDATA[android.util.AndroidRuntimeException]]></category>
		<category><![CDATA[錯誤]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[java.lang.RuntimeException: Stub!]]></category>
		<category><![CDATA[FLAG_ACTIVITY_NEW_TASK]]></category>
		<category><![CDATA[startActivity()]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=6507</guid>

					<description><![CDATA[<p>小蛙在更新「我的股票精算師」的時候沒辦法上傳 apk 到 Play 商店，錯誤提示 targetSdkVersion 要從 26 提高到 28，小蛙照做之後，卻又得到這個錯誤「java.lang.Ru&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/6507/%e5%8d%87%e7%b4%9a-api-28-%e4%b9%8b%e5%be%8c%e5%99%b4%e5%87%ba%e7%9a%84%e5%85%a9%e5%80%8b-runtimeexception-%e8%99%95%e7%90%86/" data-wpel-link="internal">targetSdkVersion 設定成 API 28 之後噴出的兩個 RuntimeException 處理</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>小蛙在更新「我的股票精算師」的時候沒辦法上傳 apk 到 Play 商店，錯誤提示 targetSdkVersion 要從 26 提高到 28，小蛙照做之後，卻又得到這個錯誤「java.lang.RuntimeException: Stub!」及「android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?」，記錄一下解決方法。</p>



<span id="more-6507"></span>



<h2 class="para wp-block-heading">java.lang.RuntimeException: Stub!</h2>



<p>看 stacktrace 裡面是用到 HttpGet 這個 function，可能在 Android 9 之後拿掉了，因此報這個錯誤。解決的方法參考這篇：<a href="https://developer.android.com/about/versions/pie/android-9.0-changes-28" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">Behavior changes: apps targeting API level 28+<span class="wpel-icon wpel-image wpel-icon-6"></span></a>。</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/qzh2CSts4UVD7pKzwgin-Byo5nLWGaGSjbh7YMgh_jD1Xl5botiL-rXcwFBD5aosLyB8me9Nhg2kx92ntv5pdYdOlYcYUzbcyYKNwLz8iSOukoRSksHvQANWfNCyZEhbiEX7nMOt2O1TIqIy1pcp4rGTCpGpBBb4N-AA-XaHGL3b4aQuiaUD9Nbqj-wyRGiPUkvrCNWc5UaltBcLf8VI4xPIy61dq-5gPLdLGm71ACsEiuhjcH_RDGlEowEEu_2wIDQkcW9usCIlTxibwGmZvz7XEEEukUvV8FvFfbZc3oOR2AASzFIakscArvqQ-VLprovUv9os1hGTqKKM9PGu4iBrqFc5ndmVacxqqAyGRH0HjmCUeWNDy8S4W0HxuZ81LEteQwxELQsnY5ADJ1i_xzUHvXZU9_dBqadrCjEA3g720rWsz-JgtUsWFn2QBijSOK2Di9HMH6r7gEWanqKUR3EYz0lRg5-H77Auol0Udncl8jYMfCJff1GC8k0LO1AWn-M_CvIoMSaL9OERGMfSmOdbXfHj07EtmZjdrJx8Gibcp_z-yU8AfMH-698DjyoxiVcH_zZQhLvvdF7mgsWJMmmYYkgCmn6FIjnRhqMwqUG_4Y672n48nrgCipHRhgDiMtQ_s8U21rj2bCDDqQ__jShcxicQSsKNl9_Olag42C0cW5EaBT6m9UkjvxRIKu_QxmbEPJaYmI0x8AqYt-j-iY1oroBCpFN8rRQ46ETZReyNcuTL=w884-h488-no" alt="qzh2CSts4UVD7pKzwgin Byo5nLWGaGSjbh7YMgh jD1Xl5botiL rXcwFBD5aosLyB8me9Nhg2kx92ntv5pdYdOlYcYUzbcyYKNwLz8iSOukoRSksHvQANWfNCyZEhbiEX7nMOt2O1TIqIy1pcp4rGTCpGpBBb4N AA XaHGL3b4aQuiaUD9Nbqj wyRGiPUkvrCNWc5UaltBcLf8VI4xPIy61dq 5gPLdLGm71ACsEiuhjcH RDGlEowEEu 2wIDQkcW9usCIlTxibwGmZvz7XEEEukUvV8FvFfbZc3oOR2AASzFIakscArvqQ VLprovUv9os1hGTqKKM9PGu4iBrqFc5ndmVacxqqAyGRH0HjmCUeWNDy8S4W0HxuZ81LEteQwxELQsnY5ADJ1i xzUHvXZU9 dBqadrCjEA3g720rWsz JgtUsWFn2QBijSOK2Di9HMH6r7gEWanqKUR3EYz0lRg5 H77Auol0Udncl8jYMfCJff1GC8k0LO1AWn M CvIoMSaL9OERGMfSmOdbXfHj07EtmZjdrJx8Gibcp z yU8AfMH 698DjyoxiVcH zZQhLvvdF7mgsWJMmmYYkgCmn6FIjnRhqMwqUG 4Y672n48nrgCipHRhgDiMtQ s8U21rj2bCDDqQ jShcxicQSsKNl9 Olag42C0cW5EaBT6m9UkjvxRIKu QxmbEPJaYmI0x8AqYt j iY1oroBCpFN8rRQ46ETZReyNcuTL=w884 h488 no targetSdkVersion 設定成 API 28 之後噴出的兩個 RuntimeException 處理" title="targetSdkVersion 設定成 API 28 之後噴出的兩個 RuntimeException 處理"></figure></div>



<p>根據官方文件，只要在 <mark class="yellow">AndroidManifest.xml</mark> 裡面加入</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">&lt;uses-library android:name="org.apache.http.legacy" android:required="false"/&gt;</pre>



<p>要加在哪裡呢？加在 &lt;application&gt; 的標籤下面就可以了</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">&lt;application&gt;
  ...
  &lt;uses-library android:name="org.apache.http.legacy" android:required="false"/&gt;
  ...
&lt;/application&gt;</pre>



<h2 class="para wp-block-heading">android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?</h2>



<p>這個問題呢是小蛙加入了 CustomTabsIntent 如果在 API 26 的時候編譯跟執行都沒有任何問題，更新到 API 28 之後一點就噴上面的錯誤，Google 了一下發現只要加入錯誤提示裡面的 flag 就可以了，修改的方式如下</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();        
// 只要加入這行就可以了
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
customTabsIntent.launchUrl(getApplicationContext(), Uri.parse(url));</pre>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/6507/%e5%8d%87%e7%b4%9a-api-28-%e4%b9%8b%e5%be%8c%e5%99%b4%e5%87%ba%e7%9a%84%e5%85%a9%e5%80%8b-runtimeexception-%e8%99%95%e7%90%86/" data-wpel-link="internal">targetSdkVersion 設定成 API 28 之後噴出的兩個 RuntimeException 處理</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/6507/%e5%8d%87%e7%b4%9a-api-28-%e4%b9%8b%e5%be%8c%e5%99%b4%e5%87%ba%e7%9a%84%e5%85%a9%e5%80%8b-runtimeexception-%e8%99%95%e7%90%86/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
