How to crash an Android app programmatically?

后端 未结 13 1487
遥遥无期
遥遥无期 2021-02-05 00:37

I want to test out crash report using acra but the first step is I need to simulate a fatal crash in Android using code.

Any idea?

相关标签:
13条回答
  • 2021-02-05 00:58

    For kotlin:

    val test = ("0")
    println(test[1])
    
    0 讨论(0)
  • 2021-02-05 01:01
    Just execute this code: divide by zero
    

    Update: Also can try this Create a method,

    public void stackOverflow() {
            this.stackOverflow();
    
        }
    

    And call this somewhere/buttonClick

    OR simply throw an uncaught exception

    throw new RuntimeException("This is a crash");
    

    Bingo!

    0 讨论(0)
  • 2021-02-05 01:01

    Don't declare activity in the Android Manifest .

    0 讨论(0)
  • 2021-02-05 01:01

    You could try a Null Pointer exception.

    Integer i = null;
    

    Then invoke any method on the object.

    i.byteValue();
    

    Invoking a method on an object that hasn't been initialized will crash the app.

    0 讨论(0)
  • 2021-02-05 01:02

    Most simple I know : throw null.

    You can't throw null, so a NullPointerException is raised.

    throw null;
    
    0 讨论(0)
  • 2021-02-05 01:03
    1. Access a view that is not defined.
    2. Access the first element of an empty list without checking.
    3. Divide by Zero.
    4. Throw the device out the window.
    5. Submerge the device in water.
    0 讨论(0)
提交回复
热议问题