我有一个奇怪的问题,活动没有启动,手机冻结了。从我从Android Studio调试时得到的logcat,以下几行不断重复。
11-04 16:04:49.956 7417-7417/com.rayat.pricewiz D/AbsListView: Get MotionRecognitionManager
11-04 16:04:49.971 7417-7417/com.rayat.pricewiz D/AbsListView: Get MotionRecognitionManager
11-04 16:04:49.976 7417-7417/com.rayat.pricewiz D/AbsListView: Get MotionRecognitionManager
11-04 16:04:49.981 7417-7417/com.rayat.pricewiz D/AbsListView: Get MotionRecognitionManager
11-04 16:04:49.981 7417-7417/com.rayat.pricewiz D/AbsListView: Get MotionRecognitionManager
11-04 16:04:49.996 7417-7417/com.rayat.pricewiz I/Timeline: Timeline: Activity_launch_request id:com.rayat.pricewiz time:2648880
11-04 16:04:50.016 7417-7417/com.rayat.pricewiz D/Activity: performCreate Call secproduct feature valuefalse
11-04 16:04:50.016 7417-7417/com.rayat.pricewiz D/Activity: performCreate Call debug elastic valuetrue
11-04 16:04:50.051 7417-7417/com.rayat.pricewiz D/AbsListView: Get MotionRecognitionManager
11-04 16:04:50.071 7417-7417/com.rayat.pricewiz I/Timeline: Timeline: Activity_launch_request id:com.rayat.pricewiz time:2648959
11-04 16:04:50.091 7417-7417/com.rayat.pricewiz D/Activity: performCreate Call secproduct feature valuefalse
11-04 16:04:50.091 7417-7417/com.rayat.pricewiz D/Activity: performCreate Call debug elastic valuetrue
这是一项简单的活动,没有复杂的工作。
布局:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@color/white"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.rayat.pricewiz.view.activity.tabshopping.ShoppingSessionCreationActivity">
<TextView style="@style/WizardPageTitle"
android:id="@+id/txtTitle"
android:text="@string/select_list" />
<com.rayat.pricewiz.view.widget.AnimatedRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button_bar"
android:layout_below="@+id/txtTitle"
android:id="@+id/llList"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:cacheColorHint="@color/transparent"
android:divider="#F0F0F0"
android:dividerHeight="0.5dp"
android:id="@+id/lsvList"
android:choiceMode="singleChoice"/>
</com.rayat.pricewiz.view.widget.AnimatedRelativeLayout>
<com.rayat.pricewiz.view.widget.AnimatedRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:layout_above="@+id/button_bar"
android:layout_below="@+id/txtTitle"
android:id="@+id/rlListDetail"
android:visibility="gone">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/light_header_grey"
android:id="@+id/hdrLists"
android:gravity="center_vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="@string/back"
android:id="@+id/btnGoBack"
android:textSize="17sp"
android:layout_marginStart="20dp"
android:fontFamily="sans-serif-light"
android:layout_alignParentStart="true"
android:background="@drawable/custom_btn_light_grey"
android:textColor="@color/grey_header_text"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:textColor="@color/black"
android:textSize="14sp"
android:id="@+id/txtListName"
android:layout_toEndOf="@+id/btnGoBack"
android:layout_toStartOf="@+id/btnOverflowMenu"
android:gravity="center"
android:layout_gravity="center_vertical"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/btnOverflowMenu"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<se.emilsjolander.stickylistheaders.ExpandableStickyListHeadersListView
android:id="@+id/listDetailView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/hdrLists"
android:background="@color/white"
android:layout_marginEnd="5dp"
android:cacheColorHint="@color/transparent"
android:divider="#F0F0F0"
android:layout_marginStart="5dp"
android:layout_marginBottom="5dp"
android:dividerHeight="0.5dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
android:id="@+id/llLoading"
android:visibility="gone">
<ProgressBar
android:id="@+id/loader2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="18dp"
android:layout_marginTop="8dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/dark_grey"
android:text="@string/loading"
android:textSize="14sp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</com.rayat.pricewiz.view.widget.AnimatedRelativeLayout>
<com.rayat.pricewiz.view.widget.AnimatedRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/txtTitle"
android:layout_above="@+id/button_bar"
android:id="@+id/layout_lstAvailableStores"
android:visibility="gone"
android:background="@color/white">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:cacheColorHint="@color/transparent"
android:divider="#F0F0F0"
android:dividerHeight="0.5dp"
android:id="@+id/lstAvailableStores"/>
</com.rayat.pricewiz.view.widget.AnimatedRelativeLayout>
<com.rayat.pricewiz.view.widget.AnimatedLinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/txtTitle"
android:layout_above="@+id/button_bar"
android:id="@+id/layout_lstSelectStore"
android:visibility="gone"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.35">
<!--<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:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.65"
android:orientation="vertical"
android:background="@color/white">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#F0F0F0"
android:dividerHeight="0.5dp"
android:background="@drawable/custom_onclick_highlight"
android:id="@+id/lstSelectedStores">
</ListView>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
<TextView
android:id="@+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="gone"/>
</LinearLayout>
</com.rayat.pricewiz.view.widget.AnimatedLinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/button_bar"
android:layout_marginBottom="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtGoBack"
style="@style/btnOrangeWhiteBackground"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:fontFamily="sans-serif-light"
android:layout_marginStart="5dp"
android:gravity="center"
android:visibility="invisible"
android:text="@string/go_back"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnSelect"
style="@style/btnFlatOrange"
android:layout_toEndOf="@+id/txtGoBack"
android:layout_toStartOf="@+id/txtCancel"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_centerInParent="true"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/select_list_for_shopping"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:text="@string/cancel"
android:layout_marginEnd="5dp"
style="@style/btnOrangeWhiteBackground"
android:gravity="center"
android:id="@+id/txtCancel"/>
</RelativeLayout>
</RelativeLayout>
代码:
public class ShoppingSessionCreationActivity extends BaseActivity implements RequestCompletionListener {
private int state;
private final int STATE_INITIAL_SCREEN = 1;
private final int STATE_STORES_TOTAL_BILL_SCREEN= 2;
private final int STATE_MERCHANT_STORES_SCREEN = 3;
private final int STATE_SESSION_STARTED_SCREEN = 4;
private final int ERROR_TYPE_LIST_NOT_SELECTED = 1;
private final int ERROR_TYPE_LIST_EMPTY = 2;
private Animation fadeIn, fadeOut;
private PleaseWaitDialog dialog;
private User user;
private MapView mapView;
private GoogleMap map;
private TextView txtTitle, txtGoBack, txtCancel, txtListname;
private AverageBillStoreAdapter averageBillStoreAdapter;
private SelectedStoresAdapter selectedStoresAdapter;
private ListSelectionAdapter listNamesAdapter;
private ListView lstAvailableStores, lstSelectedStores,lstLists;
private AnimatedRelativeLayout rlListDetail, rlAvailableStores, rlLists;
private AnimatedLinearLayout llSelectedStores;
private Button btnSelect, btnGoBack;
private String selectedListRID;
private ListAdapter mListAdapter;
private ExpandableStickyListHeadersListView mListDetailView;
private boolean mapLoaded;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inflateLayout(R.layout.activity_shopping_session_creation);
setupActionBar(getResources().getString(R.string.title_activity_shopping_session_creation), true);
checkActiveSession();
setupUI(savedInstanceState);
loadListNames();
}
public void setupUI(Bundle savedInstanceState){
final Location location = getCurrentLocation();
user = getLoggedUser();
fadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
fadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out);
dialog = new PleaseWaitDialog(this,getResources().getString(R.string.getting_local_stores_header),
getResources().getString(R.string.getting_local_stores_detail));
dialog.setCancelable(false);
selectedListRID = "";
txtTitle = (TextView)findViewById(R.id.txtTitle);
rlLists = (AnimatedRelativeLayout)findViewById(R.id.llList);
rlLists.setInAnimation(fadeIn);
rlLists.setOutAnimation(fadeOut);
rlListDetail = (AnimatedRelativeLayout)findViewById(R.id.rlListDetail);
rlListDetail.setInAnimation(fadeIn);
rlListDetail.setOutAnimation(fadeOut);
rlAvailableStores = (AnimatedRelativeLayout) findViewById(R.id.layout_lstAvailableStores);
rlAvailableStores.setInAnimation(fadeIn);
rlAvailableStores.setOutAnimation(fadeOut);
llSelectedStores = (AnimatedLinearLayout) findViewById(R.id.layout_lstSelectStore);
llSelectedStores.setInAnimation(fadeIn);
llSelectedStores.setOutAnimation(fadeOut);
lstLists = (ListView)findViewById(R.id.lsvList);
listNamesAdapter = new ListSelectionAdapter(this);
lstLists.setAdapter(listNamesAdapter);
mListAdapter = new ListAdapter(this);
mListDetailView = (ExpandableStickyListHeadersListView)findViewById(R.id.listDetailView);
mListDetailView.setOnHeaderClickListener(new StickyListHeadersListView.OnHeaderClickListener() {
@Override
public void onHeaderClick(StickyListHeadersListView l, View header, int itemPosition, long headerId, boolean currentlySticky) {
ImageView arrow = (ImageView) header.findViewById(R.id.imgArrow);
if (mListDetailView.isHeaderCollapsed(headerId)) {
mListDetailView.expand(headerId);
arrow.setImageDrawable(getResources().getDrawable(R.drawable.arrow_down));
} else {
mListDetailView.collapse(headerId);
if (Locale.getDefault().getISO3Language().equals("eng")) {
arrow.setImageDrawable(getResources().getDrawable(R.drawable.arrow_right));
} else {
arrow.setImageDrawable(getResources().getDrawable(R.drawable.arrow_left));
}
}
}
});
mListDetailView.setAdapter(mListAdapter);
btnGoBack = (Button)findViewById(R.id.btnGoBack);
btnGoBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadListNames();
}
});
txtListname = (TextView)findViewById(R.id.txtListName);
btnSelect = (Button)findViewById(R.id.btnSelect);
btnSelect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
com.rayat.pricewiz.entity.List item = listNamesAdapter.getSelectedListRID();
if (item != null) {
selectedListRID = item.getListRID();
ListItemDataSource listItemDataSource = new ListItemDataSource();
List<ListItem> listItems = listItemDataSource.getListItemsByListRID(selectedListRID);
if (listItems.size() > 0) loadStores(selectedListRID);
else showListSelectionError(ERROR_TYPE_LIST_EMPTY);
} else {
showListSelectionError(ERROR_TYPE_LIST_NOT_SELECTED);
}
}
});
lstAvailableStores = (ListView)findViewById(R.id.lstAvailableStores);
lstAvailableStores.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
rlAvailableStores.setVisibility(View.GONE);
llSelectedStores.setVisibility(View.VISIBLE);
Store2 store2 = (Store2) averageBillStoreAdapter.getItem(i);
getMerchantStores(Integer.toString(store2.getMerchantRefKey()));
state = STATE_MERCHANT_STORES_SCREEN;
}
});
averageBillStoreAdapter = new AverageBillStoreAdapter(this,location);
lstAvailableStores.setAdapter(averageBillStoreAdapter);
selectedStoresAdapter = new SelectedStoresAdapter(this,location);
lstSelectedStores = (ListView)findViewById(R.id.lstSelectedStores);
lstSelectedStores.setAdapter(selectedStoresAdapter);
lstSelectedStores.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
final int position = i;
IDialogButtonClickListener listener = new IDialogButtonClickListener() {
@Override
public void buttonOkClick(Object obj) {
createSession((Store2) selectedStoresAdapter.getItem(position), selectedListRID);
}
};
ConfirmDialog confirmDialog = new ConfirmDialog(ShoppingSessionCreationActivity.this, listener, getResources().getString(R.string.confirm_store_selection_header),
getResources().getString(R.string.confirm_store_selection_details));
confirmDialog.show();
}
});
txtTitle = (TextView)findViewById(R.id.txtTitle);
txtGoBack = (TextView)findViewById(R.id.txtGoBack);
txtCancel = (TextView)findViewById(R.id.txtCancel);
txtGoBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (state == STATE_MERCHANT_STORES_SCREEN) {
loadStores(selectedListRID);
} else if (state == STATE_STORES_TOTAL_BILL_SCREEN) {
loadListNames();
}
}
});
// Gets to GoogleMap from the MapView and does initialization stuff
/*map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
@Override
public void onMapLoaded() {
mapLoaded = true;
}
});*/
}
public void loadListNames(){
state = STATE_INITIAL_SCREEN;
ListDataSource dataSource = new ListDataSource();
java.util.List<com.rayat.pricewiz.entity.List> lists = dataSource.getLists();
listNamesAdapter.updateData(lists);
listNamesAdapter.notifyDataSetChanged();
changeView(state);
}
}
以下是我从主要活动开始的方式:
Intent intent = new Intent(context, ShoppingSessionCreationActivity.class);
startActivity(intent);
过了一会儿,我收到了OOM错误:
11-04 16:11:10.036 7417-7417/com.rayat.pricewiz E/CrashlyticsCore: Failed to execute task.
11-04 16:11:10.036 7417-7417/com.rayat.pricewiz E/CrashlyticsCore: java.util.concurrent.TimeoutException
11-04 16:11:10.036 7417-7417/com.rayat.pricewiz E/CrashlyticsCore: at java.util.concurrent.FutureTask.get(FutureTask.java:176)
11-04 16:11:10.036 7417-7417/com.rayat.pricewiz E/CrashlyticsCore: at com.crashlytics.android.core.CrashlyticsExecutorServiceWrapper.executeSyncLoggingException(CrashlyticsExecutorServiceWrapper.java:44)
11-04 16:11:10.036 7417-7417/com.rayat.pricewiz E/CrashlyticsCore: at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:275)
11-04 16:11:10.036 7417-7417/com.rayat.pricewiz E/CrashlyticsCore: at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
11-04 16:11:10.036 7417-7417/com.rayat.pricewiz E/CrashlyticsCore: at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: FATAL EXCEPTION: main
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: Process: com.rayat.pricewiz, PID: 7417
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 186636 byte allocation with 177056 free bytes and 172KB until OOM
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:747)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:568)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.content.res.Resources.loadDrawableForCookie(Resources.java:3747)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.content.res.Resources.loadDrawable(Resources.java:3620)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.content.res.Resources.getDrawable(Resources.java:1852)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.content.res.Resources.getDrawable(Resources.java:1818)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at com.rayat.pricewiz.request.WebImageLoader.displayImage(WebImageLoader.java:31)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at com.rayat.pricewiz.view.activity.BaseActivity.onCreate(BaseActivity.java:127)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at com.rayat.pricewiz.view.activity.tabshopping.ShoppingSessionCreationActivity.onCreate(ShoppingSessionCreationActivity.java:103)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6289)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:177)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.os.Looper.loop(Looper.java:145)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5942)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
11-04 16:11:10.136 7417-7417/com.rayat.pricewiz E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
任何建议出了什么问题?
修改:
Android Manifest
编辑2:
当我调试时,我发现它一次又一次地调用onCreate
方法
谢谢, Noorul
答案 0 :(得分:0)
感谢@trololo,我认为由于sqlite数据库中的数据损坏,两个活动相互启动。