Search code examples
javaandroidsqlitecrudsql-delete

how I can Call the Function from DBhandler class to My other Activity


In DBhandler class I have a function of removeAll( ) I want When My MaincashierActivity start data All data from SQLite Table Should be removed

// DBhandler class
 public void removeAll() {
    SQLiteDatabase db = this.getWritableDatabase(); 
    db.delete("TABLE_Users", null, null);
}

I want to Call this Function in my MaincashierActivit when this Activity Strat All data in SQLite databse should removed

//MaincashierActivity
public class MaincasheirActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maincasheir);





  }

 }

Solution

  • So if your SQLite has already been created already, then in MaincasheirActivity you just need to, declare DBhandler and use method removeAll:

    DBhandler dbhandler = new DBhandler();
    dbhandler.removeAll();