当我使用setHomeButton(true)返回父级时,应用程序崩溃

时间:2015-05-05 07:52:44

标签: android egl

我正在构建一个显示ListView的应用,然后在点击button后,它会更改为另一个ListView

当我点击item上的list view时,我使用setHomeButtonEnabled转到父Sctivity

       // Here i create a homebutton
        // a homebutton that is standard in andorid
        // The homebutton goes too parent_activity and
        // in the manifest i defined parent_activity as main activity

        getSupportActionBar().setHomeButtonEnabled(true);

这有效,但是当我回到父活动后使用此方法时:

package com.wordpress.elektroniknu.elektroniknu;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class ProductActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product);

        Intent intent = this.getIntent();           //Create new Intent for receiving category
        Category category = (Category) intent.getSerializableExtra("Category");     //receive category

        new setAdapter().execute(category);         //execute new Thread for the ListView in Category
        if(category.getProductList().size() == 0)
        {
            Toast.makeText(getBaseContext(), "inga erbjudanden", Toast.LENGTH_SHORT).show();

        }

        // Here i create a homebutton
        // a homebutton that is standard in andorid
        // The homebutton goes too parent_activity and
        // in the manifest i defined parent_activity as main activity

        getSupportActionBar().setHomeButtonEnabled(true);





        getSupportActionBar().setTitle(category.getCategoryName());



    }


    //DEFINE THE THREAD
    public class setAdapter extends AsyncTask<Category, Void, String> {

        @Override
        protected String doInBackground(Category... category) {
            ListAdapter theAdapter = new productsAdapter(ProductActivity.this, category[0].getProductArray());  //Get all products in Category
            ListView theListView = (ListView) findViewById(R.id.ProductListView);
            theListView.setAdapter(theAdapter);
            return(category[0].getCategoryName());
        }

        @Override
        protected void onPostExecute(String string) {
            //Toast when thread is executed
            Toast.makeText(getBaseContext(), string, Toast.LENGTH_LONG).show();
        }
    }
  /*  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_product, menu);
        return true;
    }*/

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

我的应用崩溃,我收到错误消息:

eglSurfaceAttrib not implemented     
Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6872d00, error=EGL_SUCCESS

我该如何解决这个问题?

我的清单文件中的代码段

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@drawable/logo_icon_white"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme"
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden|orientation|screenSize">
    </activity>
    <activity
        android:name=".StorePdfActivity"
        android:label="@string/title_activity_store_pdf"
        android:theme="@style/CustomTheme"
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden|orientation|screenSize">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.wordpress.elektroniknu.elektroniknu.MainActivity"/>
    </activity>
    <activity
        android:name=".ProductActivity"
        android:label="@string/title_activity_product"
        android:theme="@style/CustomTheme"
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden|orientation|screenSize"
        >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.wordpress.elektroniknu.elektroniknu.MainActivity"/>
    </activity>
    <activity
        android:name=".WelcomeActivity"
        android:label="@string/title_activity_welcome"
        android:theme="@style/CustomTheme"
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

这是Logcat:

05-05 10:22:54.060 2712-2732/com.wordpress.elektroniknu.elektroniknu D/OpenGLRenderer﹕ Render dirty regions requested: true 05-05 10:22:54.075 2712-2728/com.wordpress.elektroniknu.elektroniknu I/art﹕ Background sticky concurrent mark sweep GC freed 6582(376KB) AllocSpace objects, 0(0B) LOS objects, 14% free, 972KB/1135KB, paused 5.488ms total 46.966ms 05-05 10:22:54.086 2712-2712/com.wordpress.elektroniknu.elektroniknu D/﹕ HostConnection::get() New Host Connection established 0xa6c77440, tid 2712 05-05 10:22:54.094 2712-2712/com.wordpress.elektroniknu.elektroniknu D/Atlas﹕ Validating map... 05-05 10:22:54.149 2712-2732/com.wordpress.elektroniknu.elektroniknu D/﹕ HostConnection::get() New Host Connection established 0xa6c3ae90, tid 2732 05-05 10:22:54.161 2712-2728/com.wordpress.elektroniknu.elektroniknu I/art﹕ Background partial concurrent mark sweep GC freed 642(49KB) AllocSpace objects, 0(0B) LOS objects, 51% free, 955KB/1979KB, paused 16.380ms total 52.116ms 05-05 10:22:54.167 2712-2732/com.wordpress.elektroniknu.elektroniknu I/OpenGLRenderer﹕ Initialized EGL, version 1.4 05-05 10:22:54.177 2712-2732/com.wordpress.elektroniknu.elektroniknu D/OpenGLRenderer﹕ Enabling debug mode 0 05-05 10:22:54.190 2712-2732/com.wordpress.elektroniknu.elektroniknu W/EGL_emulation﹕ eglSurfaceAttrib not implemented 05-05 10:22:54.190 2712-2732/com.wordpress.elektroniknu.elektroniknu W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6c7a1a0, error=EGL_SUCCESS

1 个答案:

答案 0 :(得分:0)

您的代码不足以帮助您的logcat很难解决您的问题。但我认为你必须检查下面的一些条件:

  1. 您应该使用活动范围AppcompatActivityActionBarActivity
  2. 您的子活动必须使用Theme.Appcompat家庭。
  3. 重新检查工具栏(操作栏)。如果它为null,请初始化它(使用android.appcompat.v7.toolbar创建工具栏(因为在android v22中不推荐使用actionbar)。