I need to show Toast at the current Activity if it come some updatings to the Service. So Service call server and if it is some updatings, I need to notificate user nevermind at which Activity he is. I try to implement it like this:
Toast.makeText(ApplicationMemory.getInstance(), "Your order "+progress+"was updated",
Toast.LENGTH_LONG).show();
where
public class ApplicationMemory extends Application{
static ApplicationMemory instance;
public static ApplicationMemory getInstance(){
return instance;
}
}
and it doesn't works. I also tried to get current Activity name with
ActivityManager am = (ActivityManager) ServiceMessages.this.getSystemService(ACTIVITY_SERVICE);
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName();
Log.d("topActivity", "CURRENT Activity ::" + componentInfo.getClassName());
But don't know how to get context object from the ComponentName.