我正在尝试为 API 7 及更高版本实现 Action Bar。
我正在使用 Android Studio 创建一个具有以下配置的新简单项目:
- 最低 SDK:API 7
- 目标 SDK:API 14
- 编译:Google APIs 14
- 主题:带深色操作栏的全息灯
- 设置Create Activity、Fragments、Navigation Drawer、Action Bar
然后在下一个屏幕中我选择空白 Activity
在最后一个屏幕上,我选择 Navigation Drawer 以获得其他功能。
我使用 API 14 在模拟器上运行应用程序,一切正常。
但是当我在带有 API 7 的模拟器上运行它时(也在真实设备上),当我按下菜单按钮时它崩溃了。
经过一些实验,我发现只有在操作栏中有溢出操作时才会发生这种情况。
我错过了什么?
所有代码均由 Android Studio 自动生成(出于测试目的进行了一些小修改)
主 Activity .java
package com.test.myapplication4.app;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.widget.DrawerLayout;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
private NavigationDrawerFragment mNavigationDrawerFragment;
private CharSequence mTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
getMenuInflater().inflate(R.menu.main, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((MainActivity) activity).onSectionAttached(
getArguments().getInt(ARG_SECTION_NUMBER));
}
}
}
NavigationDrawerFragment.java
package com.test.myapplication4.app;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class NavigationDrawerFragment extends Fragment {
private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
private NavigationDrawerCallbacks mCallbacks;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private ListView mDrawerListView;
private View mFragmentContainerView;
private int mCurrentSelectedPosition = 0;
private boolean mFromSavedInstanceState;
private boolean mUserLearnedDrawer;
public NavigationDrawerFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
if (savedInstanceState != null) {
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
mFromSavedInstanceState = true;
}
selectItem(mCurrentSelectedPosition);
}
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
}));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
public boolean isDrawerOpen() {
return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
}
public void setUp(int fragmentId, DrawerLayout drawerLayout) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(),
mDrawerLayout,
R.drawable.ic_drawer,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).commit();
}
getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
};
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
private void selectItem(int position) {
mCurrentSelectedPosition = position;
if (mDrawerListView != null) {
mDrawerListView.setItemChecked(position, true);
}
if (mDrawerLayout != null) {
mDrawerLayout.closeDrawer(mFragmentContainerView);
}
if (mCallbacks != null) {
mCallbacks.onNavigationDrawerItemSelected(position);
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallbacks = (NavigationDrawerCallbacks) activity;
} catch (ClassCastException e) {
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
}
}
@Override
public void onDetach() {
super.onDetach();
mCallbacks = null;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
if (item.getItemId() == R.id.action_example) {
Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
private void showGlobalContextActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setTitle(R.string.app_name);
}
private ActionBar getActionBar() {
return ((ActionBarActivity) getActivity()).getSupportActionBar();
}
public static interface NavigationDrawerCallbacks {
void onNavigationDrawerItemSelected(int position);
}
}
菜单.xml
<menu 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"
tools:context="com.test.myapplication4.app.MainActivity" >
<item android:id="@+id/action_example"
android:title="@string/action_example"
app:showAsAction="withText|ifRoom" />
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
app:showAsAction="ifRoom" />
<item android:id="@+id/action_settings1"
android:title="@string/action_settings"
app:showAsAction="ifRoom" />
</menu>
activity_main.xml
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.myapplication4.app.MainActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left"
android:name="com.test.myapplication4.app.NavigationDrawerFragment" />
</android.support.v4.widget.DrawerLayout>
fragment _main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.test.myapplication4.app.MainActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
fragment_navigation_drawer.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#cccc"
tools:context="com.test.myapplication4.app.NavigationDrawerFragment" />
来自真实设备的过滤 logcat
03-22 18:01:53.665 21494-21498/com.test.myapplication4.app D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
03-22 18:01:53.745 21494-21494/com.test.myapplication4.app D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 85K, 49% free 2793K/5379K, external 0K/0K, paused 24ms
03-22 18:01:53.945 21494-21494/com.test.myapplication4.app D/CLIPBOARD﹕ Hide Clipboard dialog at Starting input: finished by someone else... !
03-22 18:01:58.450 21494-21494/com.test.myapplication4.app I/dalvikvm﹕ Could not find method android.widget.LinearLayout$LayoutParams.<init>, referenced from method android.support.v7.internal.view.menu.ActionMenuView$LayoutParams.<init>
03-22 18:01:58.450 21494-21494/com.test.myapplication4.app W/dalvikvm﹕ VFY: unable to resolve direct method 8048: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
03-22 18:01:58.450 21494-21494/com.test.myapplication4.app D/dalvikvm﹕ VFY: replacing opcode 0x70 at 0x0000
03-22 18:01:58.450 21494-21494/com.test.myapplication4.app D/dalvikvm﹕ VFY: dead code 0x0003-0007 in Landroid/support/v7/internal/view/menu/ActionMenuView$LayoutParams;.<init> (Landroid/support/v7/internal/view/menu/ActionMenuView$LayoutParams;)V
03-22 18:02:31.810 21494-21494/com.test.myapplication4.app W/KeyCharacterMap﹕ No keyboard for id 0
03-22 18:02:31.810 21494-21494/com.test.myapplication4.app W/KeyCharacterMap﹕ Using default keymap: /system/usr/keychars/qwerty.kcm.bin
03-22 18:02:31.900 21494-21494/com.test.myapplication4.app D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 116K, 48% free 2920K/5511K, external 500K/513K, paused 65ms
按下菜单按钮后来自真实设备的额外 logcat
03-22 18:02:31.930 2801-3147/? D/InputReader﹕ Input event: value=0
03-22 18:02:31.930 2801-3146/? I/InputDispatcher﹕ Delivering key to current input target: action: 1, channel '40b1ef40 com.test.myapplication4.app/com.test.myapplication4.app.MainActivity (server)'
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ Build fingerprint: 'samsung/GT-I9100/GT-I9100:2.3.6/GINGERBREAD/XWKK5:user/release-keys'
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ pid: 21494, tid: 21494 >>> com.test.myapplication4.app <<<
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000001
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ r0 00000000 r1 00000007 r2 fffffe84 r3 00000070
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ r4 0000ae28 r5 40537570 r6 ad3d3a00 r7 00000001
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ r8 001af348 r9 001af398 10 00000001 fp 442f85b8
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ ip ad3d487c sp bebe1368 lr ad35e425 pc a8115e10 cpsr 20000030
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d0 414000003f800000 d1 0000000043160000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d2 0000000000000000 d3 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d4 bf80000000000000 d5 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d6 3f80000000000000 d7 4080000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d8 0000000000000000 d9 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d10 0000000000000000 d11 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d12 0000000000000000 d13 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d14 0000000000000000 d15 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d16 0000000300000001 d17 bff0000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d18 3ff0000000000000 d19 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d20 0000000000000000 d21 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d22 3ff0000000000000 d23 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d24 3ff0000000000000 d25 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d26 0000000000000000 d27 0000000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d28 010f000001090000 d29 407c300000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ d30 0000000000000000 d31 3ff0000000000000
03-22 18:02:32.035 10167-10167/? I/DEBUG﹕ scr 60000010
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ #00 pc 00015e10 /system/lib/libutils.so
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ #01 lr ad35e425 /system/lib/libandroid_runtime.so
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ code around pc:
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ a8115df0 f4026412 ea44457f ea442405 f841221c
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ a8115e00 33012023 1003f990 dbea428b bf00bd30
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ a8115e10 2001f990 3002f990 f99018d1 f1113003
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ a8115e20 18d00208 47700080 47706800 b10b6803
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ a8115e30 e0012000 68886881 bf004770 33fff04f
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ code around lr:
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ ad35e404 f8d24629 465a71a0 46204603 f1ba47b8
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ ad35e414 d0590f00 7030f89d 980db32f ee4ef7ce
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ ad35e424 68204601 22c0f8d0 47904620 b9104607
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ ad35e434 4478484c 6821e7b4 22004620 3378f8d1
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ ad35e444 47984639 b9104682 44784847 980de7a8
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ stack:
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe1328 40556780
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe132c 00000000
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe1330 40556780
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe1334 0000d088
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe1338 40556780
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe133c 8034c10b /system/lib/libdvm.so
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe1340 40537570
03-22 18:02:32.170 10167-10167/? I/DEBUG﹕ bebe1344 442f85b8
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1348 40556780
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe134c 8034bff1 /system/lib/libdvm.so
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1350 0000ae28
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1354 40537570
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1358 ad3d3a00
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe135c 8034bfbd /system/lib/libdvm.so
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1360 df002777
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1364 e3a070ad
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ #00 bebe1368 00000001
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe136c afd149f9 /system/lib/libc.so
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1370 001af2a0
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1374 00000000
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1378 00000000
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe137c 00000000
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1380 001aed30
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1384 40557a90
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1388 001af310
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe138c ad3d3200
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1390 00000002
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1394 001af348
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe1398 001af201
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe139c 00000000
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe13a0 00000000
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe13a4 00000000
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe13a8 40537570
03-22 18:02:32.175 10167-10167/? I/DEBUG﹕ bebe13ac 001af348
03-22 18:02:32.485 10167-10167/? I/DEBUG﹕ dumpstate /data/log/dumpstate_app_native.txt
03-22 18:02:32.490 21671-21671/? I/dumpstate﹕ begin
03-22 18:02:33.295 2801-3142/? E/lights﹕ write_int: path /sys/devices/virtual/misc/melfas_touchkey/brightness, value 2
03-22 18:02:33.295 2801-3142/? W/PowerManagerService﹕ Timer 0x7->0x3|0x0
03-22 18:02:33.295 2801-3142/? I/PowerManagerService﹕ Ulight 7->3|0
03-22 18:02:33.295 2801-3142/? D/PowerManagerService﹕ setLightBrightness : mButtonLight : 0
03-22 18:02:35.290 2581-2688/? D/VoldCmdListener﹕ asec list
03-22 18:02:36.170 21671-21671/? I/dumpstate﹕ done
03-22 18:02:36.230 2801-2807/? I/ActivityManager﹕ Process com.test.myapplication4.app (pid 21494) has died.
03-22 18:02:36.230 2801-2801/? I/WindowManager﹕ WIN DEATH: Window{40b1ef40 com.test.myapplication4.app/com.test.myapplication4.app.MainActivity paused=false}
03-22 18:02:36.230 2801-2801/? W/WindowManager﹕ Window Window{40b1ef40 com.test.myapplication4.app/com.test.myapplication4.app.MainActivity paused=false} destroyed surface Surface(name=com.test.myapplication4.app/com.test.myapplication4.app.MainActivity, identity=-1, mNativeSurface=0), session Session{40a8af28 uid 10112}
03-22 18:02:36.235 2588-2588/? D/Zygote﹕ Process 21494 terminated by signal (11)
03-22 18:02:36.245 2801-3295/? I/OrientationDebug﹕ [pwm] in updateOrientationListenerLp()
03-22 18:02:36.245 2801-3295/? V/OrientationDebug﹕ in updateOrientationListenerLp(), Screen status=true, current orientation=1, SensorEnabled=true
03-22 18:02:36.245 2801-3295/? I/OrientationDebug﹕ [pwm] needSensorRunningLp(), return true #4
03-22 18:02:36.250 6072-6072/? I/GLThread﹕ onResume tid=10
03-22 18:02:36.250 6072-6072/? I/Main thread﹕ onResume waiting for !mPaused.
03-22 18:02:36.250 6072-6081/? I/GLThread﹕ mPaused is now false tid=10
03-22 18:02:36.250 6072-6072/? I/Launcher﹕ onResume(). mIsNewIntent : false screenOff: true
03-22 18:02:36.255 6072-6072/? D/Launcher﹕ It's image wallpaper. suggestDesiredDimensions(-1,-1)
最佳答案
您没有提及您运行的是什么版本的 Android Studio 或什么版本的 Android Gradle 插件,但我猜它分别是 0.5.1 和 0.9.1。如果这是真的,那么您遇到了错误 https://code.google.com/p/android/issues/detail?id=67376 ,即 0.9.1 中的 PNG 处理代码生成的 PNG 导致 Gingerbread 崩溃,原因仍在调查中。从该错误的评论 #10 中,您可以选择以下两种解决方法之一:
just add next lines to your build.gradle in order to use 0.9.1 plugin or just downgrade to 0.9.0
// Use old PNG cruncher because of crashes on GB android.aaptOptions.useAaptPngCruncher = true
如果您没有运行 0.9.1 版的 Android Gradle 插件,那么这不是您的错误。
关于android - 当 API 7 上有溢出操作时,菜单按钮会使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22578965/
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc
是否可以在应用程序中包含的gem代码中知道应用程序的Rails文件系统根目录?这是gem来源的示例:moduleMyGemdefself.included(base)putsRails.root#returnnilendendActionController::Base.send:include,MyGem谢谢,抱歉我的英语不好 最佳答案 我发现解决类似问题的解决方案是使用railtie初始化程序包含我的模块。所以,在你的/lib/mygem/railtie.rbmoduleMyGemclassRailtie使用此代码,您的模块将在
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD