What are the best ways to crash Android apps?
What are the best ways to ca开发者_开发技巧use Android apps to crash? We are trying to make our app as rock solid as possible.
For my own contribution, if you have an app that uses network services, go into your app with wifi connected and then turn off wifi in various ways. For instance, walking out of range, or backgrounding the app and manually shutting wifi off, then foregrounding the app.
Start your application, carry out some actions, change the orientation multiple times, exit the application. Repeat the process again and again to discover any hidden memory leaks (use a memory profiler).
Use the monkey to find any possible ab-use cases that you have not considered (although he is not available on some Android devices).
From experience, the best way to really test your application is to find yourself a bunch of beta testers who have not been involved in the project (their actions will make you raise an eyebrow - 'You did what!?').
I'm listing below the ways of crashing app
- Try putting a Toast in thread.
- Change orientation while fetching data in RSS feed.
- Click Back button while using tabbar. (it crashes in custom tabbar)
- Click Back button on TabGroupActivity without overriding back function.
In addition to the excellent list by Maulik:
- change screen orientation in any activity that spawns AsyncTasks
You need fast fingers :) just tap very fast on navigation proceed and back buttons, if you have them. I found a lot of crashes using this way.
If you are trying to crash intentionally to test services or how the app behaves after a crash then null context it is.
Toast.makeText(null, "Crashed before shown.", Toast.LENGTH_SHORT).show();
You can generate a null pointer exception by the below code.
- Dividing by zero-
Integer a;
a=6/0;
- creating a button-
Button a;
a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {}})
精彩评论