Work with SQLite in Android Annex



  • Salute all the locals. I came here with another question. Anyway, there's an Internet store with a list of categories, goods, brands, orders. When the application is launched, I ask the server for up-to-date lists of all of this and keep them in the OBD system and, when the application is reopened, this procedure is repeated and the annex falls on OutOfMemoryError.

    In MainActivity, I'm building a database and calling services to fill it.

    DataSource dataSource = new DataSource(this);
    startService(new Intent(this, DataBaseDownloadService.class));
    

    In DataBaseDownloadService, I go to classes that send requests to servers and return me the lists I run the cycle and add every element to the OBD system.

     categoryList = categoryDAO.downloadCategories();
     productList = productDAO.downloadProducts();
     brandList = brandDAO.dowmloadBrands();
     orderList = orderDAO.downloadOrders();
    
    for (Category category : categoryList) {
        categoryDAO.addCategory(category);
    }
    
    for (Product product : productList) {
        productDAO.addProduct(product);
    }
    
    for (Brand brand : brandList) {
        brandDAO.addBrand(brand);
    }
    
    for (Order order : orderList) {
        orderDAO.addOrder(order);
    }
    

    Question: How can this function be organized so that the OBD would be loaded only when the first application is launched, and in all subsequent launches, only an updated list of goods can be downloaded for example?



    1. In the launch, check if there's anything in the database. If so, don't start the whole store.
    2. The update can be arranged differently. For example, handing over the server of the collo-bo loaded elements from the base and loading new ones if there are more on the server. Which can be solved, for example, at timestamp.

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2