我想我有记忆问题.. 我正在构建一个应用程序,其主列表视图包含帖子,并在帖子上单击启动其他活动,列表视图显示帖子,评论等。
第一对邮政入口顺利进行,但是一对夫妇花了很多时间才开始活动..我注意到当这个小伙子发生时,我的记忆显示器发疯了(如附图所示) 。 它会像这样持续大约30秒,然后再次恢复正常,活动就会显现出来。
这个问题每次都会发生,每隔2-4次就会发生..
我不知道它是否重要提及,但是我将主要活动的post对象发送到parcelable的子活动,据我所知,当我使用intent.getParcelableExtra(“post”)时会发生滞后)。
memory monitor http://srv1.jpg.co.il/5/548974bcf03c6.jpg
这是调用意图
Intent movingToNewActivityPost = new Intent(
CustomArrayAdapterForeMainJsonParser.context,
InsidePost.class);
movingToNewActivityPost.putExtra("post",postsArray.get(position-1));
Log.i("post to inside",postsArray.get(position-1).getTitle());
movingToNewActivityPost.putExtra("from", "main");
movingToNewActivityPost.putExtra("position",position-1);
CustomArrayAdapterForeMainJsonParser.context
.startActivity(movingToNewActivityPost);
if(getCurrentAsync()!=null)
getCurrentAsync().cancel(true);
这是getView:
View row = convertView;
final ViewHolder holder;
final int type = getItemViewType(position);
// if first time you load this line
if (row == null) {
holder = new ViewHolder();
if (type == 0) {
//main post
row = inflater.inflate(R.layout.new_post_inside,
null, true);
//holder.postImage= (ImageView) row.findViewById(R.id.postImage);
holder.postTitle= (TextView) row.findViewById(R.id.postTitle1);
holder.postDate= (TextView) row.findViewById(R.id.postDate);
holder.postTags= (TextView) row.findViewById(R.id.textViewTags);
holder.postLikes = ((TextView) row
.findViewById(R.id.postLikesMain));
holder.postComments = ((TextView) row
.findViewById(R.id.postCommuntsMain));
holder.postShares = ((TextView) row
.findViewById(R.id.postSharesMain));
shares=holder.postShares;
holder.like_share_communt = (LinearLayout) row
.findViewById(R.id.share_like_communt);
holder.postLikesImage = (ImageView) row
.findViewById(R.id.imageViewLike);
holder.linearForDots= (LinearLayout) row.findViewById(R.id.linearForDots);
holder.postDescription= (TextView) row.findViewById(R.id.postBody);
holder.postCommentsTitle = (TextView) row.findViewById(R.id.commentsTitle);
holder.viewPager= (ViewPager) row.findViewById(R.id.viewPager);
parms = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
parms.width = MainActivity.screenWidth;
parms.height = (int) Math.round(MainActivity.screenWidth/1.6);
holder.linearForViewPager=(LinearLayout) row
.findViewById(R.id.linearForViewPager);
holder.linearForViewPager.setLayoutParams(parms);
holder.postCommuntsMain= (TextView) row.findViewById(R.id.postCommuntsMain);
holder.PostDivider=(View)row.findViewById(R.id.view1);
holder.postTagsImage= (ImageView) row.findViewById(R.id.imageView1);
changeFonts(holder.postTitle, "Bold");
changeFonts( holder.postDescription, "Regular");
changeFonts(holder.postDate,"Regular");
changeFonts(holder.postTags, "Regular");
changeFonts(holder.postLikes, "Regular");
changeFonts(holder.postComments,"Regular");
changeFonts(holder.postShares, "Regular");
changeFonts(holder.postCommentsTitle, "Regular");
row.setTag(holder);
}
if (type == 1) {
//comment
row = inflater.inflate(R.layout.inside_post_users_communts, null, true);
holder.commentUserName= (TextView) row.findViewById(R.id.txtName);
holder.commentDate= (TextView) row.findViewById(R.id.txtDate);
holder.commentDescription= (TextView) row.findViewById(R.id.user_communts_description);
holder.commentVotesUp= (TextView) row.findViewById(R.id.textViewVoteUp);
holder.commentVotesUpImage= (ImageView) row.findViewById(R.id.imageViewVotesUp);
holder.commentVotesDown= (TextView) row.findViewById(R.id.textViewVoteDown);
holder.commentVotesDownImage= (ImageView) row.findViewById(R.id.imageViewVotesDown);
changeFonts(holder.commentUserName, "Regular");
changeFonts(holder.commentDate,"Regular");
changeFonts(holder.commentDescription, "Regular");
changeFonts(holder.commentUserName, "Regular");
changeFonts(holder.commentVotesUp,"Regular");
changeFonts(holder.commentVotesDown, "Regular");
row.setTag(holder);
}
} else
holder = (ViewHolder) row.getTag();
if(type==0) {
final Post myPost = (Post) postsArray.get(0);
holder.postTitle.setText(myPost.getFullTitle());
holder.postDescription.setText(myPost.getDescription());
holder.postDate.setText(myPost.getPubDate()+" • "+myPost.getPubDateTime());
holder.postLikes.setText(myPost.getLikes());
holder.postShares.setText(myPost.getShares());
holder.postComments.setText(myPost.getComments());
if (myPost.getIsLiked() == 1) {
holder.postLikesImage.setImageResource(R.drawable.heart_yellow);
holder.postLikesImage.setTag("like");
} else {
holder.postLikesImage.setImageResource(R.drawable.heart_white);
holder.postLikesImage.setTag("likeoff");
}
// like
holder.like_share_communt.getChildAt(2).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.postLikesImage.getTag() == null
|| holder.postLikesImage.getTag().equals(
"likeoff")) {
holder.postLikesImage
.setImageResource(R.drawable.heart_yellow);
holder.postLikesImage.setTag("like");
int temp = Integer.parseInt(myPost.getLikes());
temp++;
holder.postLikes.setText(temp + "");
insidePost.post.setIsLiked(1);
insidePost.post.setLikes(temp + "");
Like_unlike.like(myPost.getId());
return;
}
if (holder.postLikesImage.getTag().equals("like")) {
holder.postLikesImage
.setImageResource(R.drawable.heart_white);
holder.postLikesImage.setTag("likeoff");
holder.postLikes.setText(myPost.getLikes());
int temp = Integer.parseInt(myPost.getLikes());
temp--;
holder.postLikes.setText(temp + "");
insidePost.post.setIsLiked(0);
insidePost.post.setLikes(temp + "");
Like_unlike.unlike(myPost.getId());
}
}
});
// share post
holder.like_share_communt.getChildAt(0).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
customDialogFragment1 cdf = new customDialogFragment1();
Bundle bundle = new Bundle();
bundle.putString("body", postShareUrl
+ myPost.getId());
bundle.putString("subject", myPost.getTitle());
cdf.setArguments(bundle);
cdf.show(((Activity) context).getFragmentManager(), "customDialogFragment1");
}
});
if (myPost.getTags().isEmpty()) {
holder.postTags.setVisibility(View.GONE);
holder.postTagsImage.setVisibility(View.GONE);
holder.PostDivider.setVisibility(View.GONE);
} else {
holder.postTags.setText(myPost.getTags());
}
if(shouldLaunchGp) {
GetBitmap gb = new GetBitmap(myPost.getImageIds(), myPost.getVideosIds(),
holder.viewPager, holder.linearForDots, holder.linearForViewPager);
gb.execute();
setGb(gb);
shouldLaunchGp=false;
}
}else {
if (type == 1) {
try {
final Comment comment = (Comment) postsArray.get(position);
if (comment.getDescripption().isEmpty()) {
row = null;
} else {
holder.commentDate.setText(comment.getDate());
holder.commentUserName.setText(comment.getUserName());
holder.commentDescription.setText(comment.getDescripption());
holder.commentVotesUp.setText(comment.getVotesUp());
holder.commentVotesDown.setText(comment.getVotesDown());
//0=no like or dislike, 1=like , 2=dislike
switch (comment.getLikeStat()) {
case 0:
holder.commentVotesDownImage.setAlpha(0.65f);
holder.commentVotesUpImage.setAlpha(0.65f);
break;
case 1:
holder.commentVotesDownImage.setAlpha(0.65f);
holder.commentVotesUpImage.setAlpha(1f);
holder.commentVotesUp.setTextColor(Color.parseColor("#43a047"));
holder.commentVotesDown.setTextColor(Color.parseColor("#333333"));
changeFonts(holder.commentVotesUp, "Bold");
changeFonts(holder.commentVotesDown, "Regular");
break;
case 2:
holder.commentVotesDownImage.setAlpha(1f);
holder.commentVotesDown.setTextColor(Color.parseColor("#43a047"));
holder.commentVotesUp.setTextColor(Color.parseColor("#333333"));
changeFonts(holder.commentVotesDown, "Bold");
changeFonts(holder.commentVotesUp, "Regular");
holder.commentVotesUpImage.setAlpha(0.65f);
break;
}
holder.commentVotesUpImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getAlpha() != 1f) {
v.setAlpha(1f);
if (holder.commentVotesDownImage.getAlpha() == 1f) {
holder.commentVotesDownImage.performClick();
changeFonts(holder.commentVotesDown, "Regular");
holder.commentVotesDown.setTextColor(Color.parseColor("#333333"));
}
changeFonts(holder.commentVotesUp, "Bold");
holder.commentVotesUp.setTextColor(Color.parseColor("#43a047"));
int votesUp = Integer.parseInt(comment.getVotesUp());
votesUp++;
holder.commentVotesUp.setText(votesUp + "");
comment.setVotesUp(votesUp + "");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<BasicNameValuePair> param = new ArrayList<>();
param.add(new BasicNameValuePair("commentId", comment.getCommentId()));
param.add(new BasicNameValuePair("deviceId", LoginData.getDeviceId()));
param.add(new BasicNameValuePair("type", "like"));
try {
jsnp.getJSONFromUrlWithpostParams(commentLike, param);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return null;
}
}.execute();
} else {
v.setAlpha(0.65f);
changeFonts(holder.commentVotesUp, "Regular");
holder.commentVotesUp.setTextColor(Color.parseColor("#333333"));
int votesUp = Integer.parseInt(comment.getVotesUp());
votesUp--;
holder.commentVotesUp.setText(votesUp + "");
comment.setVotesUp(votesUp + "");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<BasicNameValuePair> param = new ArrayList<>();
param.add(new BasicNameValuePair("commentId", comment.getCommentId()));
param.add(new BasicNameValuePair("deviceId", LoginData.getDeviceId()));
param.add(new BasicNameValuePair("type", "pin"));
try {
jsnp.getJSONFromUrlWithpostParams(commentLike, param);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return null;
}
}.execute();
}
}
});
holder.commentVotesDownImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getAlpha() != 1f) {
v.setAlpha(1f);
if (holder.commentVotesUpImage.getAlpha() == 1f) {
holder.commentVotesUpImage.performClick();
changeFonts(holder.commentVotesUp, "Regular");
holder.commentVotesUp.setTextColor(Color.parseColor("#333333"));
}
changeFonts(holder.commentVotesDown, "Bold");
holder.commentVotesDown.setTextColor(Color.parseColor("#d32f2f"));
int votesDown = Integer.parseInt(comment.getVotesDown());
votesDown++;
holder.commentVotesDown.setText(votesDown + "");
comment.setVotesUp(votesDown + "");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<BasicNameValuePair> param = new ArrayList<>();
param.add(new BasicNameValuePair("commentId", comment.getCommentId()));
param.add(new BasicNameValuePair("deviceId", LoginData.getDeviceId()));
param.add(new BasicNameValuePair("type", "dislike"));
try {
jsnp.getJSONFromUrlWithpostParams(commentDislike, param);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return null;
}
}.execute();
} else {
v.setAlpha(0.65f);
changeFonts(holder.commentVotesDown, "Regular");
holder.commentVotesDown.setTextColor(Color.parseColor("#333333"));
int votesDown = Integer.parseInt(comment.getVotesDown());
holder.commentVotesDown.setText(votesDown + "");
comment.setVotesUp(votesDown + "");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
ArrayList<BasicNameValuePair> param = new ArrayList<>();
param.add(new BasicNameValuePair("commentId", comment.getCommentId()));
param.add(new BasicNameValuePair("deviceId", LoginData.getDeviceId()));
param.add(new BasicNameValuePair("type", "pin"));
try {
jsnp.getJSONFromUrlWithpostParams(commentDislike, param);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return null;
}
}.execute();
}
}
});
}
}catch (Exception e){
Log.i("exception","error while loading comments-"+e.toString());
}
}
}
return row;