我有一个活动,其中包含一个名为infoViewFragment的片段,其中包含一个Google Map和另一个名为profileViewFragment的片段。
我想切换活动,但是当我在旧活动中调用startActivity()和finish()时,我收到致命信号11。
我已将其缩小到谷歌地图片段是问题的根本原因,因为我只在调用getMap()时收到致命信号,因此地图视图已初始化,但我不知道如何处理这个问题。
这是我的LogCat:
06-04 06:17:35.918: D/dalvikvm(11504): Not late-enabling CheckJNI (already on)
06-04 06:17:36.028: D/dalvikvm(11504): GC_FOR_ALLOC freed 65K, 6% free 2997K/3180K, paused 0ms, total 3ms
06-04 06:17:36.028: I/dalvikvm-heap(11504): Grow heap (frag case) to 13.415MB for 10886412-byte allocation
06-04 06:17:36.068: D/dalvikvm(11504): GC_FOR_ALLOC freed 2K, 2% free 13626K/13812K, paused 26ms, total 26ms
06-04 06:17:36.148: D/(11504): HostConnection::get() New Host Connection established 0xb7d55cf0, tid 11504
06-04 06:17:36.178: W/EGL_emulation(11504): eglSurfaceAttrib not implemented
06-04 06:17:36.178: D/OpenGLRenderer(11504): Enabling debug mode 0
06-04 06:17:41.138: D/DEBUG(11504): 00000000-40c0-4ae1-ffff-ffff99d603a9
06-04 06:17:41.138: D/DEBUG(11504): performLogin() Passing: Guest
06-04 06:17:41.188: D/dalvikvm(11504): GC_FOR_ALLOC freed 150K, 2% free 15496K/15772K, paused 2ms, total 3ms
06-04 06:17:41.198: W/Restarun(11504): GPS coordinates not found!
06-04 06:17:41.198: W/Restarun(11504): Falling back to predefined coordinates
06-04 06:17:41.719: I/u(11504): Making Creator dynamically
06-04 06:17:41.719: I/Google Maps Android API(11504): Google Play services client version: 4452000
06-04 06:17:41.719: I/Google Maps Android API(11504): Google Play services package version: 4452036
06-04 06:17:41.749: I/fpp(11504): Making Creator dynamically
06-04 06:17:41.749: I/Google Maps Android API(11504): Google Play services client version: 4452000
06-04 06:17:41.779: D/dalvikvm(11504): GC_FOR_ALLOC freed 1543K, 10% free 16002K/17656K, paused 17ms, total 17ms
06-04 06:17:41.779: D/dalvikvm(11504): GC_FOR_ALLOC freed 15K, 9% free 16106K/17656K, paused 3ms, total 3ms
06-04 06:17:41.779: I/dalvikvm-heap(11504): Grow heap (frag case) to 16.910MB for 1127532-byte allocation
06-04 06:17:41.789: D/dalvikvm(11504): GC_FOR_ALLOC freed 0K, 9% free 17207K/18760K, paused 2ms, total 2ms
06-04 06:17:41.879: D/dalvikvm(11504): GC_FOR_ALLOC freed 436K, 7% free 17575K/18760K, paused 3ms, total 4ms
06-04 06:17:41.879: I/dalvikvm-heap(11504): Grow heap (frag case) to 20.393MB for 3276812-byte allocation
06-04 06:17:41.899: D/dalvikvm(11504): GC_FOR_ALLOC freed 2K, 6% free 20772K/21964K, paused 14ms, total 14ms
06-04 06:17:42.809: D/dalvikvm(11504): GC_FOR_ALLOC freed 1018K, 5% free 21802K/22932K, paused 3ms, total 6ms
06-04 06:17:43.159: W/EGL_emulation(11504): eglSurfaceAttrib not implemented
06-04 06:17:43.159: I/Choreographer(11504): Skipped 76 frames! The application may be doing too much work on its main thread.
06-04 06:17:48.199: D/(11504): HostConnection::get() New Host Connection established 0xb81a7360, tid 11536
06-04 06:17:48.249: D/dalvikvm(11504): GC_FOR_ALLOC freed 4535K, 20% free 19294K/23944K, paused 5ms, total 7ms
06-04 06:17:48.579: D/dalvikvm(11504): GC_FOR_ALLOC freed 1408K, 17% free 19889K/23944K, paused 18ms, total 18ms
06-04 06:17:48.779: D/dalvikvm(11504): GC_FOR_ALLOC freed 1903K, 17% free 20033K/23944K, paused 5ms, total 5ms
06-04 06:17:49.159: D/dalvikvm(11504): GC_FOR_ALLOC freed 2006K, 17% free 20075K/23944K, paused 5ms, total 5ms
06-04 06:17:53.509: D/DEBUG(11504): Performing logout
06-04 06:17:53.579: W/EGL_emulation(11504): eglSurfaceAttrib not implemented
06-04 06:17:53.969: A/libc(11504): Fatal signal 11 (SIGSEGV) at 0x00000002 (code=1), thread 11536 (Thread-399)
相关代码:
public void doLogout(View view) {
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.remove( viewInfoFragment );
transaction.remove( profileInfoFragment );
transaction.commit();
Intent intent = new Intent( this, MainActivity.class );
Bundle args = new Bundle();
args.putBoolean( "logout", true );
intent.putExtras( args );
startActivity( intent );
this.finish();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_search );
/* Retrieve the login information from the previous activity */
Bundle b = getIntent().getExtras();
mUser.m_name = b.getString( "user_name" );
mUser.m_fbPhoto = b.getString( "FB_photo" );
mUser.beenPlaces = new ArrayList<Place>();
mUser.favoritedPlaces = new ArrayList<Place>();
/* Preload all layout fragments */
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.add( R.id.container, viewInfoFragment );
transaction.add( R.id.container, profileInfoFragment );
transaction.hide( viewInfoFragment );
transaction.hide( profileInfoFragment );
transaction.commit();
/* Find the user's current location */
Location m_location = new ServiceGPS( this ).getLocation();
/* Attempt to pass phone's GPS latitude and longitude */
try {
mPlaces = new YelpAPI().execute( m_location.getLatitude(),
m_location.getLongitude() ).get();
} catch (NullPointerException e) {
/* Default to pre-set coordinates in case GPS fails */
try {
Log.w( "Restarun",
"GPS coordinates not found!\nFalling back to predefined coordinates" );
mPlaces = new YelpAPI().execute( 32.8762142, -117.2354577 )
.get();
} catch (InterruptedException | ExecutionException e1) {
e1.printStackTrace();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
/* Select a random restaurant in the list and move it to first position */
Random rand = new Random();
int pos = rand.nextInt( mPlaces.size() );
Collections.swap( mPlaces, 0, pos );
/* Load the list view */
mPager = (ViewPager) findViewById( R.id.pager );
mPager.setAdapter( new MyAdapter( getSupportFragmentManager() ) );
mPager.setOffscreenPageLimit( mPlaces.size() );
}
public void setMap(String m_name, String m_address) {
Geocoder coder = new Geocoder( this );
Address location = null;
try {
List<Address> addressList;
addressList = coder.getFromLocationName( m_address, 5 );
if ( addressList != null ) {
location = addressList.get( 0 );
}
} catch (IOException e) {
e.printStackTrace();
}
if ( location != null ) {
LatLng Restaurant = new LatLng( location.getLatitude(),
location.getLongitude() );
mGoogleMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById( R.id.map )).getMap();
if ( mGoogleMap != null ) {
mGoogleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(
Restaurant, 15 ) );
mGoogleMap.clear();
mGoogleMap.addMarker(
new MarkerOptions().position(
new LatLng( location.getLatitude(), location
.getLongitude() ) ).title( m_name ) )
.showInfoWindow();
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fraginfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:gravity="center_horizontal"
tools:context="${packageName}.${activityClass}" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="@+id/info_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Name" />
<TextView
android:id="@+id/info_addr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Address" />
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="eatHere"
android:text="Eat Here" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/linearLayout1"
android:onClick="addFavorite"
android:text="Add to Favorites" />
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:0)
没有足够的评论评论...但我有同样的问题。但是,它只发生在基于haxm的仿真器上。在真实的设备上到目前为止还没有问题。我很想相信它在模拟器中的一个错误......但在发布产品之前,这是一个可怕的假设。