question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make BaseCrashReportDialog extend AppCompatActivity

See original GitHub issue

Background

I’m currently developing a custom crash report dialog, and I want it to be a full-screen dialog, as shown below: Screenshot_20190311-121431

I’ve extended BaseCrashReportDialog, and I need to add the “X” in the top-left corner and the “Send” button in the top-right corner. I am using the following code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    ActionBar supportActionBar = getSupportActionBar();
    assert supportActionBar != null;
    supportActionBar.setDisplayHomeAsUpEnabled(true);
    supportActionBar.setHomeAsUpIndicator(R.drawable.close);
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.report_problem, menu);
    return true;
}

Problem

However, I cannot call getSupportActionBar() because the base class doesn’t extend AppCompatActivity. As a result, I cannot put an “X” in the top-left corner in a way that works on all OS versions.

Solutions

I can think of a few ways to deal with this:

  • Use AppCompatDelegate as suggested in #443. The problem with this is it requires me to write a large amount of boilerplate code so is quite messy. Plus, there are still some behaviours that are built into AppCompatActivity but not AppCompatDelegate.
  • Change BaseCrashReportDialog to extend from AppCompatActivity. I think this is a more reasonable base class than the current FragmentActivity. But I suppose this could be a breaking change… 😞
  • Change BaseCrashReportDialog into a fragment that developers can include into their own activities. This way you still get a lot of control and the ability to hook into the activity but without dictating the class hierarchy for the activity itself.

Edit: actually I ended up deciding not to go ahead with ACRA (due to GDPR), but I’ll still leave this issue open in case you’re interested.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
F43nd1rcommented, Mar 11, 2019

I think I’d prefer to allow any activity as dialog, and encapsulate all logic in BaseCrashReportDialog in a POJO.

0reactions
F43nd1rcommented, Mar 12, 2019

There are no sources in the repository for it, as this “Class [is] generated based on AcraDialog

(Quote from http://www.acra.ch/javadoc/latest/org/acra/config/DialogConfiguration.html)

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - How to extend AppCompatActivity for an activity which ...
AppCompatActivity ; import java.util.ArrayList; public class Exter extends AppCompatActivity{ public static ArrayList<HashMap<String, ...
Read more >
AppCompatActivity - Android Developers
public class AppCompatActivity extends FragmentActivity implements AppCompatCallback, TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.
Read more >
Introducing the Activity - CommonsWare
When you create a new project, it is very likely that you will be given an activity that extends from AppCompatActivity .
Read more >
9. WHAT IS APPCOMPATACTIVITY IN ANDROID STUDIO
In this video you will understand in detail what is AppCompatActivity with simple real life examples.
Read more >
Different Ways to fix Cannot resolve symbol ... - GeeksforGeeks
When you create a project and extends activity AppCompatActivity, sometimes you must have observed Android Studio throws an error that is:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found