vendredi 4 septembre 2015

Display variable data from SQLite using base adapter and listview

Hi I am working on application consists of json notification that comes from parse and the application store it in SQLite i did that task but there is a big Problem to me and it is that i want to show stored notifications in a listview to display it in main activity that is my code

public class Receiver extends ParsePushBroadcastReceiver {


 @Override
    public void onPushReceive(Context context, Intent intent) {
        super.onPushReceive(context, intent);
        Log.e("Push", "Clicked");
        Intent i = new Intent(context, splashscreen.class);
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i); 


        Log.d("Alert: ", "Inserting from onReceive"); 
        Bundle extras = intent.getExtras();
        String jsonData = extras.getString("com.parse.Data");
        JSONObject jsonObject;
        try {
            jsonObject = new JSONObject(jsonData);
            String alert = jsonObject.getString("alert");
            Log.d("Insert: ",alert); 
            String Message = jsonObject.getString("Message");
            Log.d("Title: ",Message); 
            String Date = jsonObject.getString("Date");
            Log.d("Date: ",Date); 


            DatabaseHandler db=new DatabaseHandler(context);

            db.addnotification(new notification(alert,Message,Date));

            Log.d("Reading: ", "Reading all notifications.."); 
            List<notification> notifications = db.getAllnotifications();       

            for (notification cn : notifications) {
                String log = "Id: "+cn.getID()+" ,Title: " + cn.gettitle() + " ,Message: " + cn.getmessage()+ " ,Date: " + cn.gettimedate();
                // Writing notifications to log
                Log.d("Name: ", log);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
}

Aucun commentaire:

Enregistrer un commentaire