Search code examples
androidbroadcastreceiver

How to change UI colors at BroadcastReceiver?


I have an Alarm Manager for update database"s values.When user starts to alarm,My broadcastReceiver is activeted.There is another alarm in my BroadcastReceiver that İt always active when first alarm launch that It works only once.My BroadcastReceiver works but It doesn"t do what I say.My purpose is:Updating UI with colors.I have 3 if loops to updating my database.My problem is I update my database but When Updated my database,Third one loop doesn"t work.I am working with Toast for understanding . How can I fix it?

First one works good:

if( !listDataBoya.contains("#1eac02")){
    Toast.makeText(context, "Alarm !!!!!!!!!!1111111111", Toast.LENGTH_LONG).show();


    String table = "people_table";
    ContentValues productDetailsContentValues = new ContentValues();
    productDetailsContentValues.put("boya", "#1eac02");
    String where = " id = " + listDataId.get(secilmissayı);
    mDatabaseHelper.update(table, productDetailsContentValues, where , null);

    setalarm(context);

}

Second one works good:

 if (listDataBoya.get(secilmissayı) != "#1eac02" ){

           String table = "people_table";
           ContentValues productDetailsContentValues = new ContentValues();
           productDetailsContentValues.put("boya", "#1eac02");
           String where = " id = " + listDataId.get(secilmissayı);
           mDatabaseHelper.update(table, productDetailsContentValues, where , null);
           Toast.makeText(context, "Alarm !!!!!!!!!!22222222"+ listDataBoya.get(secilmissayı), Toast.LENGTH_LONG).show();
           setalarm(context);

 }

Third one It doesn"t work: (I can"t see my Toast.)

if (listDataBoya.get(secilmissayı) ==  "#1eac02" ){
       Toast.makeText(context, "Alarm !!!!!!!!!!333333333", Toast.LENGTH_LONG).show();

        String table = "people_table";
        ContentValues productDetailsContentValues = new ContentValues();
        productDetailsContentValues.put("boya", "#1eac02");
        String where = " id = " + listDataId.get(secilmissayı);
        mDatabaseHelper.update(table, productDetailsContentValues, where , null);

        setalarm(context);}

Solution

  • Your third example isn't firing because you're comparing string objects with == instead you should use an equals method that will return true if the argument is a string object that represents the same sequence of characters as the string object you're comparing. Similarly you should change your other examples accordingly.

    if(listDataBoya.get(secilmissayı).equals("#1eac02")){
        ...
    }