我只是做我的項目,但當我測試我的應用程序時,我發現,然後我通過使用多個手指觸摸屏幕我的應用程序可能會啓動兩三個不同的活動。 活動全部進入後退堆棧。這是Android框架中的錯誤嗎?但我無法重現這種狀況,它只是發生了。如何避免startActivty(new Intent())方法啓動多個Activities?
那麼,你們有沒有這個問題?請來和我討論。如果你這樣做;謝謝。
供應:
這裏是我的xml文件,當我點擊不同的RelativeLayout在同一時間,它發生了。
我今天下午試過了,但是這種情況不再出現了。現在我很困惑。
<LinearLayout android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/appDefaultSingleBlockBackground"
android:layout_height="wrap_content">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:background="@drawable/mine_bg"
android:id="@+id/mine_goto_personal_info_btn"
>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:id="@+id/mine_nick_and_avatar"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="@style/TextTitle"
android:textColor="@color/appDefaultSingleBlockBackground"
android:text=""/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="@+id/mine_goto_interesting_venue"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="@style/TextNomal"
android:drawableLeft="@drawable/information_attentionbutton"
android:text="@string/myAtentionVenue"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="@+id/mine_goto_setting"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="@style/TextNomal"
android:drawableLeft="@drawable/information_setbutton"
android:text="@string/setting"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="@+id/mine_goto_youhuijuan"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="@style/TextNomal"
android:drawableLeft="@drawable/information_discountbutton"
android:text="@string/youhuijuan"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="@+id/mine_goto_my_rest_money"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="@style/TextNomal"
android:drawableLeft="@drawable/information_balancebutton"
android:text="@string/myRest"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="@+id/mine_goto_secure"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="@style/TextNomal"
android:drawableLeft="@drawable/information_accountssafebutton"
android:text="@string/secure"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividerdefault"
/>
</LinearLayout>
這是我的java代碼。
private void init(View ret) {
final TextView txtAvatar = (TextView) ret.findViewById(R.id.mine_nick_and_avatar);
final RelativeLayout gotoPersonal = (RelativeLayout) ret.findViewById(R.id.mine_goto_personal_info_btn);
RelativeLayout gotoInterest = (RelativeLayout) ret.findViewById(R.id.mine_goto_interesting_venue);
RelativeLayout gotoSetting = (RelativeLayout) ret.findViewById(R.id.mine_goto_setting);
RelativeLayout gotoYouhuijuan = (RelativeLayout) ret.findViewById(R.id.mine_goto_youhuijuan);
RelativeLayout gotoMyRestMoney = (RelativeLayout) ret.findViewById(R.id.mine_goto_my_rest_money);
RelativeLayout gotoSecure = (RelativeLayout) ret.findViewById(R.id.mine_goto_secure);
gotoPersonal.setTag("gotoPersonal");
gotoInterest.setTag("gotoInterest");
gotoSetting.setTag("gotoSetting");
gotoYouhuijuan.setTag("gotoYouhuijuan");
gotoMyRestMoney.setTag("gotoMyRestMoney");
gotoSecure.setTag("gotoSecure");
try {
Object o = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[1]);
if (o != null && !"null".equals(o)) {
txtAvatar.setText((String) o);
} else {
o = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[10]);
if (o != null && !"null".equals(o))
txtAvatar.setText("KD" + o);
}
} catch (Exception e) {
}
Object o1 = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[2]);
if (o1 != null)
MyApplication.downloader.download("http://" + o1, new ImageDownloadStateListener() {
@Override
public void loading() {
}
@Override
public void loadSuccess(Bitmap bitmap, String url) {
try {
bitmap = Tools.transforCircleBitmap(bitmap);
BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
gotoPersonal.measure(0, 0);
int measuredHeight = gotoPersonal.getMeasuredHeight();
LogHelper.print("==height" + measuredHeight);
drawable.setBounds(0, 0, measuredHeight/5 * 4, measuredHeight/5 * 4);
txtAvatar.setCompoundDrawables(drawable, null, null, null);
} catch (Exception e) {
//no nothing
}
}
@Override
public void loadFailed() {
}
});
gotoPersonal.setOnClickListener(this);
gotoInterest.setOnClickListener(this);
gotoSetting.setOnClickListener(this);
gotoYouhuijuan.setOnClickListener(this);
gotoMyRestMoney.setOnClickListener(this);
gotoSecure.setOnClickListener(this);
}
@Override
public void onResume() {
initActionBar();
super.onResume();
MobclickAgent.onPageStart(getClassName()); //統計頁面
}
@Override
public void onPause() {
super.onPause();
MobclickAgent.onPageEnd(getClassName());
}
private String getClassName() {
String canonicalName = this.getClass().getCanonicalName();
String[] split = canonicalName.split("\\.");
return split[split.length - 1];
}
private void initActionBar() {
MyActivity activity = (MyActivity) mActivity;
activity.setActionBarLeftImg(new ColorDrawable(Color.TRANSPARENT), false);
activity.setActionBarRightImg(new ColorDrawable(Color.TRANSPARENT));
activity.setOnActionBarLeftClickListener(null);
activity.setOnActionBarRightClickListener(null);
activity.setActionBarTitle("個人中心");
}
@Override
public void onClick(View v) {
Object tag = v.getTag();
if (tag != null) {
String str = (String) tag;
if (mActivity == null) {
return;
}
if (!((MyActivity) (mActivity)).isLogin) {
Intent intent = new Intent(mActivity, LoginActivity.class);
startActivity(intent);
return;
}
if (!TextUtils.isEmpty(str))
if ("gotoPersonal".equals(str)) {
Intent intent = new Intent(mActivity, PersonalInfoActivity.class);
startActivity(intent);
} else if ("gotoInterest".equals(str)) {
Intent intent = new Intent(mActivity, VenueListActivity.class);
intent.putExtra("isInterests", true);
startActivity(intent);
} else if ("gotoSetting".equals(str)) {
Intent intent = new Intent(mActivity, SettingActivity.class);
startActivity(intent);
} else if ("gotoYouhuijuan".equals(str)) {
Intent intent = new Intent(mActivity, FavorableActivity.class);
startActivity(intent);
} else if ("gotoSecure".equals(str)) {
Intent intent = new Intent(mActivity, SecureActivity.class);
startActivity(intent);
} else if ("gotoMyRestMoney".equals(str)) {
Intent intent = new Intent(mActivity, MyRestActivity.class);
startActivity(intent);
}
}
}
請提供您如何啓動活動,你想怎麼回他們等之間導航這件事的詳細信息通過在帖子中包含你的代碼。 – Melquiades
請添加相應活動的代碼。 – Melquiades
感謝您的耐心。 – innershows