我有一个通知服务,它每 5 秒触发一次,获取数据并解析它,然后显示它。但这种机制仅适用于应用程序的主屏幕。
我希望在应用程序的每个屏幕上都这样做。为此,我应该在项目的每个活动中编写相同的代码吗?这是一项非常乏味的工作。我想让它概括..
怎么做 ??有任何想法吗??
我有一个通知服务,它每 5 秒触发一次,获取数据并解析它,然后显示它。但这种机制仅适用于应用程序的主屏幕。
我希望在应用程序的每个屏幕上都这样做。为此,我应该在项目的每个活动中编写相同的代码吗?这是一项非常乏味的工作。我想让它概括..
怎么做 ??有任何想法吗??
you can make BasicActivity
and have method in that Activity
and call that method inside onCreate();
now extend every Activity in your project from your BasicActivity
If you are talking push notification service, this idea seems to problematic. tell us more what are you exactly trying to do.
you do something like this in some utility class
public static void showNotifction(Activity a)
{
//notify
}
and over this if you have any call back methods.. Then create an interface with those methods and implement them in all those Activities and you can do this..
public static void showNotifction(CommoInterface a)
{
if(a insatncof Activity){
//notify
a.callBack(); // callBack is a method in the interface..
}
}