应用程序暂停一小时或多小时后关闭应用程序

时间:2016-08-17 09:30:14

标签: android

我有一个订单拍摄屏幕,其中有4000 +代码行。当我从这个特定活动暂停应用程序时,由于空指针异常,我被强制关闭。我发现几个对象无效,用于TextView onClick监听器,当我重新启动应用程序时。我在onPause()和onRestart()中执行了以下代码,如下所示。但仍然得到相同的强制关闭。

enter code here


    @Override
    protected void onPause() {
        super.onPause();
        Toast.makeText(getApplicationContext(), "pause started", Toast.LENGTH_SHORT).show();
        ViewConstants.timeOfPause = 0;
        ViewConstants.timeOfPause = System.currentTimeMillis();
    }

@Override
    protected void onRestart() {
        super.onRestart();
        long applicationIdleTime = Math.abs(ViewConstants.timeOfPause - System.currentTimeMillis());
        if (applicationIdleTime >= 5000) {
            Toast.makeText(getApplicationContext(), "restart >5 second", Toast.LENGTH_SHORT).show();
            clearFields();
            ViewConstants.PRODUCT_FIRST_LOAD = true;
            ViewConstants.CATEGORY_FIRST_LOAD = true;
            Intent intent = new Intent(NewOrderActivity.this, NewOrderActivity.class);
            startActivity(intent);
            finish();

        } else if (stockOrderPreference == null ||
                MBQOrderPreference == null ||
                priceOrderPreference == null ||
                quantityOrderPreference == null ||
                firstDiscountOrderPreference == null ||
                secondlDiscountOrderPreference == null ||
                actualStockOrderPreference == null ||
                perlitreSchemePreference == null ||
                freeQtyPreference == null ||
                salesPromotionPreference == null ||
                decimalOrderQuantity == null ||
                orderBlockWithStock == null ||
                mobileschemePreference == null ||
                mapOrderPreference == null ||
                taxOrderPreference == null) {
            Toast.makeText(getApplicationContext(), "restart due to null", Toast.LENGTH_SHORT).show();
            clearFields();
            ViewConstants.PRODUCT_FIRST_LOAD = true;
            ViewConstants.CATEGORY_FIRST_LOAD = true;
            Intent intent = new Intent(NewOrderActivity.this, NewOrderActivity.class);
            startActivity(intent);
            finish();
        }

0 个答案:

没有答案