I am trying to get a handle on some issues my Android app is having which I think are related to memory pressure when I am running in explicit \"foreground\" mode (Service.s
EDIT: (taking into account Christoph's comment)
You can create artificial memory pressure. To do so, create a button in your MainActivity. Then, in the button's onClick
method, create 10,000 objects (experiment with different amounts of objects). Then, while your app is running, click that button numerous times which should create a lot of memory pressure.
The code could look like this:
class MainActivity {
ArrayList<String> stringArray = new ArrayList<>();
...
public void click(View view) {
// Add 10,000 String objects to Array List
for (int i = 0; i < 10000; i++) {
stringArray.add("A string");
}
}
}
Assuming that you set the button's onClick
XML attribute to click
.