简体   繁体   中英

StartActivity from Application closes app

I've got a class that extends the Application, and from there, on shake detection, it should open up an activity. However, for a specific Activity it closes the app instead. There are NO crashes or errors in the logs which is making this really hard to debug...

Code is as follows to start the activity:

                int currentViewingMemberId = CommonFunctions.get_CURRENT_VIEWING_MEMBER_ID(this);
                Bitmap b = takeScreenshot();
                Intent contactAndReportIntent = ReportIssueActivity.getIntentForActivity(getApplicationContext(), true, null, b, currentViewingMemberId);
                contactAndReportIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(contactAndReportIntent);

                mSensorManager.unregisterListener(this);
                hasAccelerometerSensorBeenRegistered = false;

getIntentForActivity() method is as follows:

public static Intent getIntentForActivity(Context context, boolean isFromShake, String helpTip, Bitmap screenshot, int currentViewingMemberId) {
        Intent intent = new Intent(context, ReportIssueActivity.class);
        intent.putExtra(FROM_SHAKE, isFromShake);
        if (helpTip == null) {
            helpTip = "";
        }
        if (screenshot != null) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            screenshot.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();
            intent.putExtra(SCREENSHOT_IMAGE, byteArray);
        }
        intent.putExtra(HELP_TIP, helpTip);
        intent.putExtra(CURRENT_VIEWING_MEMBER_ID, currentViewingMemberId);
        return intent;
    }

takeScreenshot() captures the current window and returns a Bitmap successfully, but the Activity onCreate() is not even called.

Any ideas would help, thanks! :)

It turns out i was getting a TransactionTooLargeException when trying to return my activity Intent. Swapping:

 screenshot.compress(Bitmap.CompressFormat.PNG, 100, stream);

for:

 screenshot.compress(Bitmap.CompressFormat.JPEG, 80, stream);

fixed it as it reduced the screenshot image size to below the allowed amount.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM