I'm building an app that shows a ListView
then after clicking a button
it changes to another ListView
.
我正在构建一个显示ListView的应用程序,然后单击一个按钮后,它将更改为另一个ListView。
When I click an item
on the list view
I use setHomeButtonEnabled
to go to the parent Sctivity
:
当我单击列表视图中的项目时,我使用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);
This works but when I use this method after I have gone back to the parent activity:
这有效,但是当我回到父活动后使用此方法时:
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);
}
}
My app crashes and I get the error messages:
我的应用程序崩溃,我收到错误消息:
eglSurfaceAttrib not implemented
Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6872d00, error=EGL_SUCCESS
How can I fix this ?
我怎样才能解决这个问题 ?
Snippet from my manifest file
我的清单文件中的代码段
<?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>
Here is the Logcat:
这是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
05-05 10:22:54.060 2712-2732 / com.wordpress.elektroniknu.elektroniknu D / OpenGLRenderer:渲染所请求的脏区:真05-05 10:22:54.075 2712-2728 / com.wordpress.elektroniknu.elektroniknu I / art:背景粘性并发标记扫描GC释放6582(376KB)AllocSpace对象,0(0B)LOS对象,14%免费,972KB / 1135KB,暂停5.488ms总计46.966ms 05-05 10:22:54.086 2712-2712 / com .wordpress.elektroniknu.elektroniknu D /:HostConnection :: get()建立新主机连接0xa6c77440,tid 2712 05-05 10:22:54.094 2712-2712 / com.wordpress.elektroniknu.elektroniknu D / Atlas:验证地图.. .05-05 10:22:54.149 2712-2732 / com.wordpress.elektroniknu.elektroniknu D /:HostConnection :: get()建立新主机连接0xa6c3ae90,tid 2732 05-05 10:22:54.161 2712-2728 / com .wordpress.elektroniknu.elektroniknu I / art:背景部分并发标记扫描GC释放642(49KB)AllocSpace对象,0(0B)LOS对象,51%免费,955KB / 1979KB,暂停16.380ms总计52.116ms 05-05 10: 22: 54.167 2712-2732 / com.wordpress.elektroniknu.elektroniknu I / OpenGLRenderer:初始化EGL,版本1.4 05-05 10:22:54.177 2712-2732 / com.wordpress.elektroniknu.elektroniknu D / OpenGLRenderer:启用调试模式0 05- 05 10:22:54.190 2712-2732 / com.wordpress.elektroniknu.elektroniknu W / EGL_emulation:eglSurfaceAttrib未实现05-05 10:22:54.190 2712-2732 / com.wordpress.elektroniknu.elektroniknu W / OpenGLRenderer:设置失败表面0xa6c7a1a0上的EGL_SWAP_BEHAVIOR,错误= EGL_SUCCESS
1 个解决方案
#1
Your code isn't enough to help and your logcat is hard to resolve your problem. But i think you must check some conditions below:
您的代码不足以帮助您的logcat很难解决您的问题。但我认为你必须检查下面的一些条件:
- You should be used Activity extends from
AppcompatActivity
orActionBarActivity
. - Your Sub Activity must be used
Theme.Appcompat
family. - Recheck your toolbar (actionbar). if it's null, please initialize it (Use
android.appcompat.v7.toolbar
for create your toolbar (because actionbar is deprecated in android v22) .
您应该使用AppcompatActivity或ActionBarActivity中的Activity扩展。
您的Sub Activity必须使用Theme.Appcompat系列。
重新检查工具栏(操作栏)。如果它为null,请初始化它(使用android.appcompat.v7.toolbar创建工具栏(因为在android v22中不推荐使用actionbar)。
#1
Your code isn't enough to help and your logcat is hard to resolve your problem. But i think you must check some conditions below:
您的代码不足以帮助您的logcat很难解决您的问题。但我认为你必须检查下面的一些条件:
- You should be used Activity extends from
AppcompatActivity
orActionBarActivity
. - Your Sub Activity must be used
Theme.Appcompat
family. - Recheck your toolbar (actionbar). if it's null, please initialize it (Use
android.appcompat.v7.toolbar
for create your toolbar (because actionbar is deprecated in android v22) .
您应该使用AppcompatActivity或ActionBarActivity中的Activity扩展。
您的Sub Activity必须使用Theme.Appcompat系列。
重新检查工具栏(操作栏)。如果它为null,请初始化它(使用android.appcompat.v7.toolbar创建工具栏(因为在android v22中不推荐使用actionbar)。