1
I have a problem where I need to alter an image of a imageView when the Button is pressed and when it is pressed again change to the image that was previously. I even managed to do this through the setBackgroundResource, the problem is when I close the app or get out of this determined Activity and I go back to her the image returns to be the one that was in  android:background from the start.
Can someone help me?
Xml code
<Button
    android:id="@+id/buttonLigarDesligar"
    android:padding="10dp"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@drawable/icone_ligar"/>
<ImageView
    android:id="@+id/imgStatus"
    android:padding="10dp"
    android:background="@drawable/icone_vermelho"
    android:layout_width="40dp"
    android:layout_height="40dp"/>
Java code
buttonLigarDesligar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int status = 0;
            if (satus == 0){ 
                imgStatus.setBackgroundResource(R.drawable.ic_on);
                status = 1;
            }else{
                imgStatus.setBackgroundResource(R.drawable.icone_vermelho);
                status = 0;                   
            }
        }
    });
}
You can store this information in a database, or ideally save it in a sharedpreferences, if no one answers you by tomorrow, I’ll help. Pq now to off pc
– Murillo Comino