Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes application crashes while receiving notification. #11

Open
WorkspacePrateek opened this issue Sep 4, 2020 · 0 comments
Open

Comments

@WorkspacePrateek
Copy link

WorkspacePrateek commented Sep 4, 2020

I am setting multiple notifications on page load. Using below function

private void setAllNotifications() {
        for (EventDetailModel eventDetail : eventList) {
            String strNotification = eventDetail.getName() + " : " + eventDetail.getDescription();
            Calendar eventDate = getDateInLocal(eventDetail.getDate());
            Calendar tempCal = Calendar.getInstance();
            tempCal.setTimeZone(TimeZone.getTimeZone("UTC"));
            if (eventDetail.getStatus() && eventDate.getTimeInMillis() > tempCal.getTimeInMillis()) {
                assert eventDetail.getId() != null;
                NotifyMe.cancel(LoadingActivity.this, eventDetail.getId()); //Remove Old Notifications
                scheduleNotification(eventDate, eventDetail.getId(), strNotification);
            }
        }
    }

    private void scheduleNotification(final Calendar cal, final String id, final String mContent) {
        Log.d(TAG, "Time: " + cal.getTime());
        cal.set(Calendar.SECOND, 0);
        Intent intent = new Intent(LoadingActivity.this, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("EventDetail", mContent);
        NotifyMe.Builder notify = new NotifyMe.Builder(LoadingActivity.this)
                .title("Rakr")
                .content(mContent)
                .time(cal)
                .addAction(intent, "Open")
                .key(id)
                .large_icon(R.drawable.main_icon);
        notify.build();
    }

But sometimes the application crashes with below Error.

09-04 23:28:00.981 31186-31186/greenapple.rakrnew E/AndroidRuntime: FATAL EXCEPTION: main
    Process: greenapple.rakrnew, PID: 31186
    java.lang.RuntimeException: Unable to start receiver com.allyants.notifyme.NotificationPublisher: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:2732)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
        at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460)
        at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
        at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
        at com.allyants.notifyme.NotificationPublisher.onReceive(NotificationPublisher.java:50)
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:2725)
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant