I started learning about Android Development, and I read about static variables are bad and may leak memory because they are not garbage collectable.
I've used some in certain situations, but I am so concerned it may leak memory.
Can someone please look at my code below and see if they leak memory or not?
MainActivity.java
public class MainActivity extends Activity {
public static boolean IS_ACTIVITY_OPEN;
public static ImageView image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
IS_ACTIVITY_OPEN = true;
....
....
VoiceReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
.....
};
registerReceiver(VoiceReceiver, new IntentFilter(BroadCastReceivers.VoiceIntent));
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(VoiceReceiver);
IS_ACTIVITY_OPEN = false;
}
}
Picture.java
MainActivity.image.setImageBitmap(resizedBitmap);
.....
.....
BroadCast.java
if (!MainAcitivty.IS_ACTIVITY_OPEN) {
//start an activity
Intent intent2 = new Intent(context, MainAcitivty.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
handler= new Handler();
MyPostDelay = new Runnable() {
@Override
public void run() {
context.sendBroadcast(new Intent(VoiceIntent));
}
};
handler.postDelayed(MyPostDelay, 300);
}
else
{
context.sendBroadcast(new Intent(VoiceleIntent));
}
Thank you very much in advance.