dimanche 24 avril 2016

What will be the Context for DBManagement class

I am making CountDownTimer for which on time reach i can delete all my database. but when i make object of DBManagment class the context problem ahead. Kindly tell me what will be the context? In log the error showing "null".

the context needs for this line dbManagement = new DBManagement();

  • the Timer class is non activity class

    private Context context;

    public Timer(long startTime, long interval)
    {
        super(startTime, interval);
    }
    
    @Override
    public void onFinish()
    {
        try {
            dbManagement = new `DBManagement(context.getApplicationContext());`
        } catch (Exception e) {
            Log.d("errorrrrrrrrr", " is " + e.getMessage());
        }
    
    }
    
    

the DBManagement class consist for following constructor:

// Constructor for creating database

public DBManagement(Context context){
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

Calling Activity:

public class Blocklist extends AppCompatActivity {
private final long startTime = 1000;
    private final long interval = 1000;
    private Timer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_blocklist);
        toolbar = (Toolbar) findViewById(R.id.toolbar);

// Count down timer
        countDownTimer = new Timer(startTime, interval);
        countDownTimer.start();
}

Aucun commentaire:

Enregistrer un commentaire