-3

ゲット例外閉じている場合、アラームがトリガー:android.database.sqlite.SQLiteException:によって引き起こさアプリがクラッシュするアプリは

をなし、そのようなテーブル: TABLE_USER_RITUALS(コード1):、コンパイル中:選択*からアプリがバックグラウンドで開いている場合は、コードが正常に動作としてUSER_NAME =「vxfbb」とRITUAL_NAME = 「朝の日課」

しかし、データベースがある TABLE_USER_RITUALSは、アプリがバックグラウンドから削除されたときに、それがクラッシュしてしまった存在します

ブロードキャストレシーバークラス:

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); 

    } 
} 
+0

はあなたがあなたの活動の破壊にデータベースを削除していないことを確認している –

+0

例外メッセージはかなり明示され、削除、データベースに変更を加えた場合、テーブルは –

+0

が欠落していますそれ以外の場合はキャッチやデータをクリアすると、すべて正常であれば問題なく動作します –

答えて

0

私は答えを持っている:

あなたはBroadcastReceiver onReceiveメソッドシグネチャの一部として持っており、それはそれだデータベースを呼び出すための、コンテキストが必要になります。 refrenceため

how can i access database from broadcast receiver in android?