Is there a way to know if some code runs in background?

Is there a way to know in MyApp.onStart whether it runs in background or glance or foreground?