我正在实施推送通知,到目前为止它工作正常.我设法获得推送通知,当我点击它能够开始活动时.
但如果应用程序已在运行,我不想通知用户有关通知的信息.这就是我计划这样做的方法......但不确定这是否正确
Intent actIntent = new Intent(this, MainActivity.class);
actIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, actIntent, 0);
if (!isActivityRunning())
mNotificationManager.notify(0, notification);
public boolean isActivityRunning(Context ctx) {
ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (RunningTaskInfo task : tasks) {
if (ctx.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName()))
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
isActivityRunning函数将基本检查MainActivity是否正在运行.如果它处于运行状态,则不会显示通知,并将信息传递给活动本身以更新UI.如果点击通知未运行活动,则会打开MainActivity.
这是实现这一目标的正确方法吗?
我在我的Android应用程序中使用PullToRefresh.到目前为止工作正常.
我面临的问题是,当我从TOP新行中下载新的x行时,推出现有行并从0位置开始,这对用户来说很烦人.我想要的是,在下载新的行集后,列表应保留在那里,让用户向下查看新的行集.
任何想法我怎么能实现这一目标?
我认为我的项目需要从ListView转移到RecyclerView.我正面临一些设计问题.
在我当前的ListView实现中,我使用CustomView而不是在那里进行膨胀.这是我当前的getView()
public View getView(int position, View containerRow, ViewGroup parent) {
CustomView customView;
if (containerRow == null) customView = new CustomView(mContext);
else customView = (CustomView) containerRow;
DataModel dataModel = getModelForPosition(position);
if (dataModel != null) {
customView.showView(singleDcyde,position);
}
return customView;
}
Run Code Online (Sandbox Code Playgroud)
这里showView管理填充textViews,图像自定义LayoutParams和许多其他东西(2000行).
现在,当我计划搬到RecylerView时,我对我的设计感到困惑. - 我是否需要在RecyclerView.ViewHolder类中重写整个内容然后在onBindViewHolder中绑定它们?
因为我已经为Listview编写了大量代码,我不想重写/移动整个东西从CustomView返回到ViewHolder.
什么是使设计与RecyclerView理念保持同步的最佳方法.