question

R. Steventon avatar image
R. Steventon asked ·

[BUG / CRASH] in MraidRenderer

Just pushed out an app with the latest SDK, and the following came pouring back via ACRA. Please fix this. Hardware SGH-T589, DROID3, SGH-T679, GT-P3113 + others 0android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 1at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4125) 2at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:716) 3at android.view.View.requestLayout(View.java:12957) 4at android.view.View.requestLayout(View.java:12957) 5at android.view.View.requestLayout(View.java:12957) 6at android.view.View.requestLayout(View.java:12957) 7at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:268) 8at android.view.View.requestLayout(View.java:12957) 9at android.view.View.requestLayout(View.java:12957) 10at android.view.View.requestLayout(View.java:12957) 11at android.view.ViewGroup.removeAllViews(ViewGroup.java:3681) 12at com.amazon.device.ads.MraidRenderer.boolean render()(SourceFile:86) 13at com.amazon.device.ads.AdController.void handleResponse()(SourceFile:439) 14at com.amazon.device.ads.AdLoader.void finalizeFetchAd()(SourceFile:273) 15at com.amazon.device.ads.AdLoader$AdFetcherTask.void onPostExecute(com.amazon.device.ads.AdLoader)(SourceFile:397) 16at com.amazon.device.ads.AdLoader$AdFetcherTask.void onPostExecute(java.lang.Object)(SourceFile:383) 17at android.os.AsyncTask.finish(AsyncTask.java:602) 18at android.os.AsyncTask.access$600(AsyncTask.java:156) 19at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615) 20at android.os.Handler.dispatchMessage(Handler.java:99) 21at android.os.Looper.loop(Looper.java:154) 22at android.os.HandlerThread.run(HandlerThread.java:60)
mobile ads
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bipin@Amazon avatar image
Bipin@Amazon answered ·
Hi, Is the ad called from the main thread(UI thread). try Loading the view example : adView.loadAd() from the activity context and check. if you are on different thread try below code. activity.runOnUiThread(new Runnable() { @Override public void run() { ..... adView.loadAd(); } }); i hope this will solve.
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

R. Steventon avatar image
R. Steventon answered ·
Just look at the crash stack I included. THE PROBLEM IS IN AMAZON CODE. In fact, I am using XML to implement the advert!!!! See here: 11at android.view.ViewGroup.removeAllViews(ViewGroup.java:3681) 12at com.amazon.device.ads.MraidRenderer.boolean render()(SourceFile:86) 13at com.amazon.device.ads.AdController.void handleResponse()(SourceFile:439) 14at com.amazon.device.ads.AdLoader.void finalizeFetchAd()(SourceFile:273) 15at com.amazon.device.ads.AdLoader$AdFetcherTask.void onPostExecute(com.amazon.device.ads.AdLoader)(SourceFile:397) 16at com.amazon.device.ads.AdLoader$AdFetcherTask.void onPostExecute(java.lang.Object)(SourceFile:383) 17at android.os.AsyncTask.finish(AsyncTask.java:602) See ? YOU GUYS are the ones who have not used runOnUiThread on YOUR AsyncTask's onPostExecute..... Now, on most devices this is not a problem. But for a number of devices (including Samsung, LG, Droid), their Android OS does NOT force the AsyncTask's onPostExecute to run on the GUI thread. This is REALLY badly documented, so I am not surprised your dev team did not know it. Please fix (so I can send you 500k+ impressions per day which are mostly Kindle)....
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

R. Steventon avatar image
R. Steventon answered ·
Guys (Kevin probably), AsyncTask's onPostExecute() does NOT ALWAYS RUN ON THE GUI thread..... ESPECIALLY on pre-4.0 Android. Since you wanted code: public class Banner extends Advert_BaseClass implements AdListener { private AdLayout amazonAd; private String network; public Banner(Context context, AttributeSet attrs) { super(context, attrs); ... determine 'network' using sharedprefs LayoutInflater layoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (network.contentEquals("mopub") || network.length() == 0) { } else if (network.contentEquals("amazon")) { AdRegistration.setAppKey("asdf"); AdTargetingOptions options = new AdTargetingOptions(); options.enableGeoLocation(true); LinearLayout layout = (LinearLayout) layoutInflater.inflate(R.layout.ad_banner_amazon, null); amazonAd = (AdLayout) layout.findViewById(R.id.adview); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); addView(layout, params); amazonAd.loadAd(options); } else if ()...... And you probably need: public abstract class Advert_BaseClass extends LinearLayout { And the layout/ad_banner_amazon.xml layout is just an Amazon XML snippet with a LinearLayout around it. The custom view ie: Banner() is created as part of a larger XML sheet whose id is passed to setContentView. amazonAd.loadAd() therefore runs in the GUI thread.
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

R. Steventon avatar image
R. Steventon answered ·
And just for good measure, get your guys to read the following: http://stackoverflow.com/questions/10426120/android-got-calledfromwrongthreadexception-in-onpostexecute-how-could-it-be Your SDK is exposing an Android Framework bug. Message was edited by: R. Steventon
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered ·
Hi Steventon, We are working on the fix for this issue. We would add the fix in the upcoming version of the sdk. Thanks.
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.