-3

Get Exception :

Caused by: android.database.sqlite.SQLiteException: no such table: TABLE_USER_RITUALS (code 1): , while compiling: Select * from TABLE_USER_RITUALS where USER_NAME = 'vxfbb' and RITUAL_NAME = 'Morning Routine'

But the database is exists as the code works fine if the app is opened in background, it got crashed when app is removed from the background

Broadcast Receiver Class:

public class AlarmReceiver extends BroadcastReceiver
{

    String h_id, habit, habit_desc, habit_time;
    //public static Ringtone ringtone;

    @Override
    public void onReceive(Context mContext, Intent arg1) 
    {
        String selectedRitual = arg1.getExtras().getString(AppsConstant.SELECTED_RITUAL);
        String userName = arg1.getExtras().getString(AppsConstant.user_name);

        // Enable {@code SampleBootReceiver} to automatically restart the alarm when the
        // device is rebooted.
        ComponentName receiver = new ComponentName(mContext, SampleBootReceiver.class);
        PackageManager pm = mContext.getPackageManager();

        pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP); 

        //get data from database        
        GetData getData = new GetData();
        UserRitualModel userReminderSetting  = getData.getRitualsDetails(userName, selectedRitual);
        int isfullScreen = userReminderSetting.getNotificationStyle();
        int ringInSilent = userReminderSetting.getRingInSilent();

        if(ringInSilent ==TableAttributes.ON)
        {
            final AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
            int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);

            audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolume,AudioManager.FLAG_ALLOW_RINGER_MODES); 
        }


        Intent i;
        if(isfullScreen==TableAttributes.ON)
        {
              i = new Intent(mContext, ReminderFullScreen.class);
        }
        else
        {
            i = new Intent(mContext, Reminder.class);  
        }
       // i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.putExtra(AppsConstant.SELECTED_RITUAL, selectedRitual);
        i.putExtra(AppsConstant.user_name, userName);

        mContext.getApplicationContext().startActivity(i);

    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Juned
  • 41
  • 6

1 Answers1

0

I have got the answer :

You will need the context,for calling the database which you have as part of the BroadcastReceiver onReceive method signature and that's it.

for refrence : how can i access database from broadcast receiver in android?

Community
  • 1
  • 1
Juned
  • 41
  • 6