Home > other >  I trying to open app but It's crushed by on Runtime Exception, How to solved this problem?
I trying to open app but It's crushed by on Runtime Exception, How to solved this problem?

Time:03-02

My Mobile version is 12. Work App properly but I upgrade my software version of mobile then crushes.

enter image description here

Show this Error on my log:

2022-03-01 12:04:55.025 31242-31291/com.Solver.Solver E/AndroidRuntime: FATAL EXCEPTION: WorkManager-WorkManagerTaskExecutor-thread-0 Process: com.Solver.Solver, PID: 31242

java.lang.IllegalArgumentException: com.Solver.Solver: Targeting S  (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.

Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
    at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
    at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:147)
    at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:124)
    at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:79)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:920)

CodePudding user response:

Your passing unexpected flags into a PendingIntent.

For example:

int intentFlags = PendingIntent.FLAG_ONE_SHOT;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
    intentFlags = PendingIntent.FLAG_ONE_SHOT|PendingIntent.FLAG_IMMUTABLE;
}

CodePudding user response:

I am solved this error.

I Implements this code.

implementation "androidx.work:work-runtime:2.7.1" 

CodePudding user response:

try this code

PendingIntent pendingIntent;
Intent openIntent = new Intent(context, QiscusPushNotificationClickReceiver.class);
openIntent.putExtra("data", comment);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            pendingIntent = PendingIntent.getBroadcast(context, QiscusNumberUtil.convertToInt(comment.getRoomId()),
                    openIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT);
} else {
    pendingIntent = PendingIntent.getBroadcast(context, QiscusNumberUtil.convertToInt(comment.getRoomId()),
                    openIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}




 <activity android:name=".MainActivity" android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
  • Related