How can I save the data from parse.com in the device’s memory?

Asked

Viewed 214 times

1

I’m trying to do something simple, but for me a little complicated, I’m trying to save the data coming from parse.with on the device, because when it has connection to the internet it works, but when it does not have, the device does not save the data in memory, so the data only appear when it has network.

I would like the data to be saved and whenever it recognizes the internet the data is synchronized, updated.

I’m trying to do that:

public class Pizzarias extends ActionBarActivity {
    // Declare Variables
    Boolean bColorStatus = true;
    TextView status;
    ListView listview;
    List<ParseObject> ob;

    ProgressDialog mProgressDialog;
    ListViewAdapterPizzarias adapter;
    private List<WorldPopulation> worldpopulationlist = null;

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

        new RemoteDataTask().execute();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_pizzarias, menu);

        //Os metodos abaixo são para mostrar o icone do aplicativo na action bar
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setLogo(R.drawable.ic_launcher);
        getSupportActionBar().setDisplayUseLogoEnabled(true);

        return true;
    }


    //RemoteDataTask AsyncTask
    private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a progressdialog
            mProgressDialog = new ProgressDialog(Pizzarias.this);
            // Set progressdialog title
            mProgressDialog.setTitle("Carregando Pizzarias");
            // Set progressdialog message
            mProgressDialog.setMessage("Aguarde...");
            mProgressDialog.setIndeterminate(false);
            // Show progressdialog
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // Create the array
            worldpopulationlist = new ArrayList<WorldPopulation>();


            try {

                String objectId = "GFiBnjCE4v";
                ParseObject feed = ParseQuery.get(objectId);
                feed.fetch();
                feed.put("fechado", true);
                feed.saveEventually();


                ParseQuery<ParseObject> query = ParseQuery.get("GerenciarPizzariasPatos")
                        .fromLocalDatastore()
                        .whereEquals("fechado", true)
                        .findInBackground(new FindCallback<ParseObject>() {
                            public void done(List<ParseObject> objects, ParseException e) {
                                // "feed" ParseObject will be returned in the list of results
                            }
                        });

                // Locate the column named "ranknum" in Parse.com and order list
                // by ascending,

                query.orderByAscending("nome");

                ob = query.find();
                for (ParseObject country : ob) {
                    WorldPopulation map = new WorldPopulation();
                    map.setNome((String) country.get("nome"));
                    map.setEndereco((String) country.get("endereco"));
                    map.setTelefone((String) country.get("telefone"));
                    map.setStatus((String) country.get("status"));
                    worldpopulationlist.add(map);

                }
            } catch (ParseException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            // Locate the listview in listview_main.xml
            listview = (ListView) findViewById(R.id.listviewpizzarias);
            // Pass the results into ListViewAdapter.java
            adapter = new ListViewAdapterPizzarias(Pizzarias.this,
                    worldpopulationlist);
            // Binds the Adapter to the ListView
            listview.setAdapter(adapter);
            // Close the progressdialog
            mProgressDialog.dismiss();

        }
    }
}

These two lines of code are giving error, appears below the get a line wavy red indicating the error.

ParseObject feed = ParseQuery.get(objectId);
ParseQuery<ParseObject> query = ParseQuery.get("GerenciarPizzariasPatos")

Mistakes:

Error:(100, 46) error: non-static method get(String) cannot be referenced from a Static context Where T is a type-variable: T extends Parseobject declared in class Parsequery

Error:(106, 59) error: non-static method get(String) cannot be referenced from a Static context Where T is a type-variable: T extends Parseobject declared in class Parsequery

Error:(107, 25) error: cannot find Symbol method fromLocalDatastore()

  • You already have the entire database structure in your application or it is from that point that you need help?

  • @Paulo Rodrigues. I have the data received from Parse.com, so I would like that when I ran out of net in the app, it left the data from the saved lists to be viewed even without internet.

  • 1

    Well, I asked that question but then I went to check that the Parse has its own methodology of local datastore.

  • @Paulo Rodrigues. I am sincere in saying that I do not know how to create a database, so I resorted to parse.com which by the way is a very good platform, but because it is a "new" technology, there are not many examples to help. I’m waiting for some answer.

  • 1

    @Filipe Oliveira. You could remove the suspension?

  • 1

    @qmechanik. You could take the suspension off?

  • @Ronysueliton suspension has been lifted.

  • @williamhk2. Thank you very much

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.