Skip to content

Commit

Permalink
Use ALooper_pollOnce instead of ALooper_pollAll (#1040)
Browse files Browse the repository at this point in the history
The latter is deprecated and will be removed in Android 34.
  • Loading branch information
jrprice authored Jun 3, 2024
1 parent 32ca240 commit 8397767
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions android_sample/jni/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <android/log.h>
#include <android/looper.h>
#include <android_native_app_glue.h>

#include "amber/amber.h"
Expand Down Expand Up @@ -93,13 +94,17 @@ void android_main(struct android_app* app) {
app->onAppCmd = handle_cmd;

// Used to poll the events in the main loop
int events;
android_poll_source* source;

// Main loop
while (app->destroyRequested == 0) {
if (ALooper_pollAll(1, nullptr, &events, (void**)&source) >= 0) {
if (source != NULL)
auto result = ALooper_pollOnce(1, nullptr, nullptr, (void**)&source);
if (result == ALOOPER_POLL_ERROR) {
LOGE("ALooper_pollOnce returned an error.");
exit(1);
}

if (result >= 0 && source != nullptr) {
source->process(app, source);
}
}
Expand Down

0 comments on commit 8397767

Please sign in to comment.