Stack Overflow Asked on December 15, 2020
Whenever I return (onResume
) to my only activity, my app crashes with the below error. My Activity contains only a Google Map and a banner ad (from Facebook Audience Network)
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 14320 (RenderThread), pid 14265
How can I fix this issue? I would appreciate your help on this. I could not find the problem as my code is very simple.
Here’s my activity_maps.xml
:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/constraintLayout"
tools:context=".MapsActivity">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<LinearLayout
android:id="@+id/banner_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Here’s my MapsActivity.java
:
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.facebook.ads.AdSize;
import com.facebook.ads.AdView;
import com.facebook.ads.AudienceNetworkAds;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
AudienceNetworkAds.initialize(this);
adView = new AdView(this, "my_placement_id", AdSize.BANNER_HEIGHT_50);
// Find the Ad Container
LinearLayout adContainer = findViewById(R.id.banner_container);
// Add the ad view to your activity layout
adContainer.addView(adView);
// Request an ad
adView.loadAd();
}
@Override
public void onMapReady(GoogleMap googleMap) {
}
}
Here’s how it looks like:
As qtmfld pointed out, your error is most likely happening in the RenderThread. My educated guess is that it has to do with your banner ad drawing on top of the map fragment.
There are known drawing issues when using hardcoded fragment elements in xml layouts, especially when using fragment transactions. Therefor, it is possible that SupportFragmentManager is somehow trying to draw over the banner ad when recreating the fragments state, which is causing the crash.
Apart from that, it is against Google's ad policies, to use banner ads above components, that the user interacts with.
To confirm this you can try changing your layout constraints so, that the banner ad doesn't overlay the maps fragment:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/banner_container"
tools:context=".MapsActivity" />
Answered by nulldroid on December 15, 2020
You Mixed up some things!
Have a look at the Facebook Documentation under: initialize-the-audience-network-sdk
You can see that they call AudienceNetworkAds.initialize(this);
in the Application class and not in the Activity.
Create a Class like in the documentation:
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize the Audience Network SDK
AudienceNetworkAds.initialize(this);
}
}
The next Step is to add the class with android:name=".YourApplication"
in the Manifest file, like in the example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.rieger.com.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".YourApplication"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
This tells Android where he can find your implementation of the Application class.
Then remove the AudienceNetworkAds.initialize(this);
line from your onCreate() Method in the class MapsActivity.
Now everything should work well.
Why does the exception show up?
Have a look at the Activity Lifecycle.
onCreate() can be called by the system at every startup of your Activity and not only onResume() or onStart().
What happens is that the emulator call onCreate() when you open the Activity for the second time over the onCreate() method. Which leads to a second call of AudienceNetworkAds.initialize(this);
which causes the error.
Another hint
Don't forget to implement the onDestroy() method like:
@Override
protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
Answered by Sebastian Rieger on December 15, 2020
Please check if you are using HAXM
based emulator and check if it also happens in real devices.
You can also try Google Maps Android SDK v.3.1.0 BETA and see if the bug still exists.
Answered by wonsuc on December 15, 2020
In the Logcat message:
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 14320 (RenderThread), pid 14265
A/libc
shows that the priority is A
(Assert) and the tag is libc
(bionic).Fatal signal 11 (SIGSEGV)
, which means that your app terminates itself, receiving a signal of segmentation violation.code 1 (SEGV_MAPERR), fault addr 0x0
details that libc
failed to read or write memory address 0x0
(null pointer), as explained in this answer.in tid 14320 (RenderThread), pid 14265
shows that this crash took place in thread 14320 (RenderThread)
of process 14265
.RenderThread
indicates that this might be due to hardware acceleration.
To turn off the acceleration, add an attribute
android:hardwareAccelerated="false"
to one of these elements in AndroidManifest.xml
.
<application />
.<activity />
that crashes.I think it's worth a try.
Answered by qtmfld on December 15, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP