我在登录后开始主要活动时遇到问题。如果我在genymotion API 19中运行应用程序就可以了。但是当我在genymotion API 21中运行应用程序它停止工作。它显示错误:
04-07 00:21:40.776: E/AndroidRuntime(3227): FATAL EXCEPTION: main
04-07 00:21:40.776: E/AndroidRuntime(3227): Process: vae.vnsupermark.com, PID: 3227
04-07 00:21:40.776: E/AndroidRuntime(3227): java.lang.RuntimeException: Unable to start activity ComponentInfo{vae.vnsupermark.com/vae.vnsupermark.com.MainActivity}: java.lang.RuntimeException: Cannot make calls to a recycled instance!
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.ActivityThread.access$800(ActivityThread.java:144)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.os.Handler.dispatchMessage(Handler.java:102)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.os.Looper.loop(Looper.java:135)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.ActivityThread.main(ActivityThread.java:5221)
04-07 00:21:40.776: E/AndroidRuntime(3227): at java.lang.reflect.Method.invoke(Native Method)
04-07 00:21:40.776: E/AndroidRuntime(3227): at java.lang.reflect.Method.invoke(Method.java:372)
04-07 00:21:40.776: E/AndroidRuntime(3227): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
04-07 00:21:40.776: E/AndroidRuntime(3227): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-07 00:21:40.776: E/AndroidRuntime(3227): Caused by: java.lang.RuntimeException: Cannot make calls to a recycled instance!
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.content.res.TypedArray.getResourceId(TypedArray.java:694)
04-07 00:21:40.776: E/AndroidRuntime(3227): at vae.vnsupermark.com.MainActivity.onCreate(MainActivity.java:216)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.Activity.performCreate(Activity.java:5933)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
04-07 00:21:40.776: E/AndroidRuntime(3227): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
04-07 00:21:40.776: E/AndroidRuntime(3227): ... 10 more
我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="vae.vnsupermark.com"
android:versionCode="7"
android:versionName="1.0.3" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21"
android:maxSdkVersion="22"
/>
<!-- for card.io card scanning -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- BLUETOOTH -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- GCM -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- gps -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="vae.vnsupermark.com.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="vae.vnsupermark.com.permission.C2D_MESSAGE" />
<!-- END GCM -->
<!-- for most things, including card.io & paypal -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name="vae.vnsupermark.config.ConfigApp"
android:configChanges="keyboardHidden|orientation|screenSize"
android:icon="@drawable/ic_app"
android:label="@string/app_name"
android:theme="@style/ThemeNoActionbar" >
<activity
android:name=".SplashActitvity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/ThemeNoActionbar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/CustomMainActionBarTheme"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".LoginActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/ThemeNoActionbar" />
<activity
android:name="vae.vnsupermark.payment.OnepayCheckout"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/ThemeNoActionbar" />
<activity
android:name="vae.vnsupermark.payment.VtcpayCheckout"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/ThemeNoActionbar" />
<activity
android:name="vae.vnsupermark.payment.PaypalCheckout"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/ThemeNoActionbar" />
<!-- GCM -->
<receiver
android:name="vae.vnsupermark.notify.GcmReceiverVNSuper"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="vae.vnsupermark.notify" />
</intent-filter>
</receiver>
<service android:name="vae.vnsupermark.notify.GcmServiceVNSuper" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- END GCM -->
<receiver android:name="vae.vnsupermark.notify.WelcomeReceiverVNSuper" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<!-- Error Reporter -->
<meta-data
android:name="de.quist.app.errorreporter.reportOnFroyo"
android:value="true" />
<meta-data
android:name="de.quist.app.errorreporter.targetUrl"
android:value="http://vnsupermark.com/android/report_error/log_error.php" />
<meta-data
android:name="de.quist.app.errorreporter.targetEmailSubject"
android:value="VNSuperMark Report Error" />
<meta-data
android:name="de.quist.app.errorreporter.targetEmailFrom"
android:value="VNSuperMark App Android" />
<service
android:name="de.quist.app.errorreporter.ExceptionReportService"
android:process=":exceptionReporter" />
<activity
android:name=".RegisterActivity"
android:label="@string/title_activity_register" >
</activity>
</application>
</manifest>
功能登录()
private void login() {
String username = edtUsername.getText().toString();
String password = edtPassword.getText().toString();
if (!username.equals("") && !password.equals("")) {
Store store = Store.getInstances(LoginActivity.this);
//info user login
HashMap<String, String> params = new HashMap<String, String>();
params.put("command", "login");
params.put("user", username);
params.put("pass", password);
if (store != null) { // if get config succcess
ConfigApp config = (ConfigApp) getApplication();
taskLoginSever = new TaskLoginSever(LoginActivity.this, params, false, config);
taskLoginSever.execute(store.getA());
} else {
new DialogCustom(LoginActivity.this).showToast(getResources().getString(R.string.error_getconfig));
}
//hide keyboard
Utils.hideKeyboard(LoginActivity.this);
}
else {
if (username.equals("")) {
edtUsername.setError(getResources().getString(R.string.no_username));
}
if (username.equals("")) {
edtPassword.setError(getResources().getString(R.string.no_password));
}
}
Taskloginserver()
private void showNotifyLogin(final boolean succcess, String message) {
final DialogCustom dialog = new DialogCustom(context, R.layout.layout_dialog_notify_login,
R.id.tv_message, message);
//object handle
final Handler handle = new Handler();
handle.postDelayed(new Runnable() {
@Override
public void run() {
// close dialog
if (dialog.isShowing())
dialog.dismiss();
if( succcess ) {
///show main, if from login activity to main activity
// else from main activity to login activity then exit Login UI
Bundle bundle = ((LoginActivity)context).getIntent().getExtras();
boolean openMain = false; //default open main activity
if(bundle != null) {
openMain = bundle.getBoolean(config.MAIN_TO_LOGIN_TAG);
}
if ( !openMain )
// open main activitycontext
((LoginActivity) context).openMainActivity();
else
// finish login activity
((LoginActivity) context).exitLoginUI();
}
//remove handle
handle.removeCallbacks(this);
}
} , 1000); //time to show dialog notify login 1s
//show dilog
dialog.show();
}
打开新活动
public void openMainActivity() {
//start main activity
Intent intentMain = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intentMain);
//destroy LoginActivity
exitLoginUI();
}
MainActivity
ExceptionReporter.register(this); // report error if app get error
super.onCreate(savedInstanceState);
Utils.setDefaultFont(MainActivity.this); // set font for activity
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
// create database
try {
Database.getInstances(MainActivity.this);
} catch (Exception e) {
}
// view menu
viewActionShopcart = getLayoutInflater().inflate(
R.layout.layout_action_shopcart, null);
tv_quantity_shopcart = (TextView) viewActionShopcart
.findViewById(R.id.tv_quantity_shopcart);
// layout left menu
leftMenu = (RelativeLayout) findViewById(R.id.left_menu);
drawerLayoutMenu = (DrawerLayout) findViewById(R.id.drawer_layout_menu);
drawerListMenu = (ListView) findViewById(R.id.list_menu);
headerAccountMenu = getLayoutInflater().inflate(
R.layout.header_account_menu, null);
tvNameUser = (TextView) headerAccountMenu
.findViewById(R.id.tv_name_user);
tvIdUser = (TextView) headerAccountMenu.findViewById(R.id.tv_id_user);
imageView = (ImageView) headerAccountMenu.findViewById(R.id.imageView1);
imageflag = (ImageView) headerAccountMenu.findViewById(R.id.imageflag);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String urlRegister = getResources().getString(
R.string.Detailaccount);
// open browser to register page
Intent itRegister = new Intent(Intent.ACTION_VIEW, Uri
.parse(urlRegister));
startActivity(itRegister);
}
});
tvEmail = (TextView) headerAccountMenu.findViewById(R.id.tv_email_user);
lnUserInfo = (LinearLayout) headerAccountMenu
.findViewById(R.id.ln_user_info);
lnUserLogin = (LinearLayout) headerAccountMenu
.findViewById(R.id.ln_user_login);
lnRateApp = (LinearLayout) findViewById(R.id.ln_rate_app);
tvRate = (TextView) findViewById(R.id.tv_rate);
btnLogin = (Button) headerAccountMenu.findViewById(R.id.btn_login);
// show rate text
tvRate.setText(String.format(getResources()
.getString(R.string.rate_app), Utils.getVersion(
MainActivity.this, 1)));
// add header user info
drawerListMenu.addHeaderView(headerAccountMenu);
// button login when user logout
btnLogin.setOnClickListener(new LoginListener());
lnRateApp.setOnClickListener(new RateAppListenner());
// function loadgroup asynctask
titleActionbars = getResources().getStringArray(
R.array.title_actionbars2);
arrayListgroup = new ArrayList<String>();
displayView(1, null);
// new TaskRandomNotification(MainActivity.this).execute();
executeLoadProduct();
executeLoadProducterm();
arrayListgroup = TaskLoadProductGroup.getmenunamegroup();
arraylistgroupterm = TaskLoadProductGroupterm.getmenunamegroup();
// arrayListgroup.add("VCoin");
titleActionbars = getTitleActionbars();
titleActionbar = titleActionbars[0];
// icons from resources
iconMenus = getResources().obtainTypedArray(R.array.icon_menus);
// Recycle the typed array
iconMenus.recycle();
drawerListMenu.setOnItemClickListener(new SlideMenuClickListener());
// setting the nav drawer list adapter
drawerListItemMenu = new ArrayList<DrawerItemMenu>();
// add home menu
drawerListItemMenu.add(new DrawerItemMenu(titleActionbars[0], iconMenus
.getResourceId(4, -1), true));
for (int i = 5; i < titleActionbars.length; i++) {
// FPT GATE
drawerListItemMenu.add(new DrawerItemMenu(titleActionbars[i],
iconMenus.getResourceId(0, -1), true));
}
// add history order menu
drawerListItemMenu.add(new DrawerItemMenu(titleActionbars[1], iconMenus
.getResourceId(5, -1), true));
// add logout menu when user info is saved on device
drawerListItemMenu.add(new DrawerItemMenu(titleActionbars[4], iconMenus
.getResourceId(2, -1), true)); // logout
adapterMenu = new DrawerMenuAdapter(MainActivity.this,
drawerListItemMenu);
drawerListMenu.setAdapter(adapterMenu);
// enabling action bar app icon and behaving it as toggle button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
titleMenu = getResources().getString(R.string.app_name);
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
drawerLayoutMenu, R.drawable.ic_menu, R.string.app_name,
R.string.app_name) {
public void onDrawerClosed(View view) {
setTitle(titleActionbar);
// calling onPrepareOptionsMenu() to show action bar icons
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
setTitle(titleMenu);
// calling onPrepareOptionsMenu() to hide action bar icons
supportInvalidateOptionsMenu();
}
};
// event toggle menu
drawerLayoutMenu.setDrawerListener(actionBarDrawerToggle);
// prepare info
prepareInfo();
//load image from url
GetXMLTask task = new GetXMLTask();
// Execute the task
task.execute(new String[] { URL });
if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(1, null);
// Check device for Play Services APK. If check succeeds, proceed
// with GCM registration.
regIdGCM();
}
// reset quantity on action menu
resetTextQuantity();
请帮助我在哪里可以更改?
答案 0 :(得分:0)
从MainActivity中删除此行并运行您的应用
iconMenus.recycle();