Calsign / APDE

Source code for APDE: Create and run Processing sketches on an Android device.
GNU General Public License v2.0
338 stars 76 forks source link

Wallpaper Export Bug #105

Closed Inertia-Squared closed 3 years ago

Inertia-Squared commented 3 years ago

Hey there, I am making a live wallpaper that uses accelerometer data and consequently needs Context from the parent Activity un order to talk to the sensor, this is fine in any typical application but (without looking at the source code, I think i might shortly though) i suspect that something like moveTaskToBack is being called prematurely which makes the program lose context. Ill show a quick snippet where this becomes an issue:

PApplet parent;
Context context;
SensorManager sensorManager;

  public AccelerometerManager(PApplet parent) {
    this.parent = parent;
    this.context = parent.getActivity();
}

public void someMethod(){
  sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
}

Returns Screenshot_20210108-142724_APDE.jpg

This only occurs in wallpaper export, and I'm not the strongest in Android Java so I could be completely off the mark here but assuming what I suspect is correct a way to solve it may be by adding a built-in method to get the parent context (that returns the parents Context as a string) which could be assigned in the onCreate method?

Really got no clue with the backend of this stuff since my experience is limited however I am fairly certain that there is no way to obtain the required Context for Wallpaper mode.

Thanks for your time, and if you have any more questions on the issue you'd like to ask feel free to and I'll get back to you when I can, I'm a little off the grid at the moment but I'll do my best to stay available in case there's anything else you need :)

Calsign commented 3 years ago

Wallpapers don't have activities (see the reference). Instead of using getActivity(), use getContext():

public AccelerometerManager(PApplet parent) {
    this.parent = parent;
    this.context = parent.getContext();
}