我在构建的应用程序中遇到了问题,该问题似乎与我在内存中使用太多最终变量有关,当我在 android 2.3 及以下版本中测试该应用程序时,它工作正常,但 4.0 及以上版本的应用程序在一段时间后崩溃,如果列表太长了,我想弄清楚的是一种方法,我可以绕过使变量成为最终变量,或者一旦它们不在视图中就可能使它们为空?下面是我的代码,任何帮助都会有很大帮助,谢谢
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
final String url = (String) data.get(position).get(4);
final String aviUrl = (String) data.get(position).get(2);
final Date theTime = (Date) data.get(position).get(3);
final String theTweetText = (String) data.get(position).get(1);
final String theRealName = (String) data.get(position).get(0);
final String theScreenName = (String) data.get(position).get(5);
Boolean isRetweeted = (Boolean) data.get(position).get(6);
final Long iD = (Long) data.get(position).get(7);
final Integer totalTweets = (Integer) data.get(position).get(8);
final Integer totalFollowers = (Integer) data.get(position).get(9);
final Integer totalFollowing = (Integer) data.get(position).get(10);
final Long tweetId = (Long) data.get(position).get(11);
Date currentDate = new Date();
if (convertView == null)
vi = inflater.inflate(R.layout.item, null);
if (isRetweeted == true) {
final String theRetweetedTxt = (String) data.get(position).get(12);
final String theRetweetedUser = (String) data.get(position).get(13);
final String theRetweetedImgUrl = (String) data.get(position).get(14);
final String theRetweetedScreenName = (String) data.get(position).get(15);
final Long rTiD = (Long) data.get(position).get(16);
final Integer rTtotalTweets = (Integer) data.get(position).get(17);
final Integer rTtotalFollowers = (Integer) data.get(position).get(18);
final Integer rTtotalFollowing = (Integer) data.get(position).get(19);
final Long rtTweetId = (Long) data.get(position).get(20);
TextView theTweet = (TextView) vi.findViewById(R.id.tweet_text);
TextView username = (TextView) vi.findViewById(R.id.username);
TextView realname = (TextView) vi.findViewById(R.id.realname);
TextView theTimeTv = (TextView) vi.findViewById(R.id.theTime);
ImageView aviimage = (ImageView) vi.findViewById(R.id.user_avatar);
ImageView image = (ImageView) vi.findViewById(R.id.imageView1);
ImageView retweeterimage = (ImageView) vi
.findViewById(R.id.retweeter_avatar);
ImageView replyImage = (ImageView) vi.findViewById(R.id.mentionbutton);
ImageView retweetImage = (ImageView) vi.findViewById(R.id.retweetbutton);
RelativeLayout profileImageLayout = (RelativeLayout) vi.findViewById(R.id.profileimagelayout);
profileImageLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, FriendProfileActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", rTiD);
intent.putExtra("totaltweets", rTtotalTweets);
intent.putExtra("totalfollowers", rTtotalFollowers);
intent.putExtra("totalfollowing", rTtotalFollowing);
intent.putExtra("useravatar", theRetweetedImgUrl);
intent.putExtra("username", theRetweetedUser);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
context.startActivity(intent);
}
});
image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, LightboxActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("thetweet", theRetweetedTxt);
intent.putExtra("theimage", url);
intent.putExtra("theuserid", rTiD);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
context.startActivity(intent);
}
});
replyImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", rTiD);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
intent.putExtra("isretweet", false);
context.startActivity(intent);
}
});
retweetImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", rTiD);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
intent.putExtra("isretweet", true);
intent.putExtra("thetweet", theRetweetedTxt);
context.startActivity(intent);
}
});
String str = (String) DateUtils.getRelativeTimeSpanString(theTime.getTime(), currentDate.getTime(),
0L, DateUtils.FORMAT_ABBREV_ALL);
theTimeTv.setText(str);
theTweet.setText(theRetweetedTxt);
username.setText("RT by @" + theScreenName);
realname.setText("@" + theRetweetedScreenName);
imageLoader.DisplayImage(theRetweetedImgUrl, aviimage);
imageLoader.DisplayImage(url, image);
imageLoader.DisplayImage(aviUrl, retweeterimage);
return vi;
} else {
TextView theTweet = (TextView) vi.findViewById(R.id.tweet_text);
TextView username = (TextView) vi.findViewById(R.id.username);
TextView realname = (TextView) vi.findViewById(R.id.realname);
TextView theTimeTv = (TextView) vi.findViewById(R.id.theTime);
ImageView aviimage = (ImageView) vi.findViewById(R.id.user_avatar);
ImageView image = (ImageView) vi.findViewById(R.id.imageView1);
ImageView replyImage = (ImageView) vi.findViewById(R.id.mentionbutton);
ImageView retweetImage = (ImageView) vi.findViewById(R.id.retweetbutton);
RelativeLayout profileImageLayout = (RelativeLayout) vi.findViewById(R.id.profileimagelayout);
profileImageLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, FriendProfileActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", iD);
intent.putExtra("totaltweets", totalTweets);
intent.putExtra("totalfollowers", totalFollowers);
intent.putExtra("totalfollowing", totalFollowing);
intent.putExtra("useravatar", aviUrl);
intent.putExtra("username", theRealName);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
context.startActivity(intent);
}
});
image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, LightboxActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("thetweet", theTweetText);
intent.putExtra("theimage", url);
intent.putExtra("theuserid", iD);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
context.startActivity(intent);
}
});
replyImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", iD);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
intent.putExtra("isretweet", false);
context.startActivity(intent);
}
});
retweetImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", iD);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
intent.putExtra("isretweet", true);
intent.putExtra("thetweet", theTweetText);
context.startActivity(intent);
}
});
ImageView retweeterimage = (ImageView) vi
.findViewById(R.id.retweeter_avatar);
retweeterimage.setImageBitmap(null);
String str = (String) DateUtils.getRelativeTimeSpanString(theTime.getTime(), currentDate.getTime(),
0L, DateUtils.FORMAT_ABBREV_ALL);
theTimeTv.setText(str);
theTweet.setText(theTweetText);
username.setText(theRealName);
realname.setText("@" + theScreenName);
imageLoader.DisplayImage(aviUrl, aviimage);
imageLoader.DisplayImage(url, image);
return vi;
}
}