2013-02-06 2 views
1

2 개의 탭이있는 TabHost 활동이 있습니다. 또한 내 응용 프로그램에는 기본적으로 두 가지 유형의 알림이 있습니다. 이제 알림 1을 클릭하고 탭 2를 클릭하고 알림 2를 클릭하여 탭 1을 열려고합니다. 따라서 알림 ID에 탭의 ID를 나타내는 알림 인 텐트를 추가합니다. 탭을 변경하려면 getHttent(). getExtra (...)를 사용하여 TabHost 활동의 onResume 메소드에서 ID를 가져 와서 Tab을 변경하려고했습니다. 이 솔루션은 대부분의 경우에 사용할 수 있습니다. 그러나 때로는 제대로 작동하지 않지만, 나는 이유를 모른다. 그것이 때때로 작동하고 때로는 그렇지 않은 이유에 대한 단서가 있습니까? 아니면이 문제를 해결하기위한 더 나은 해결책이 있습니까?알림의 의도와 함께 탭을 변경합니다.

답변

0

이렇게하려면 ActivityGroups를 사용해야합니다.

http://united-coders.com/nico-heid/use-android-activitygroup-within-tabhost-to-show-different-activity

http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html

그러나, 액티비티 그룹은 ICS에서 사용되지 않습니다 점에 유의하십시오. 탭에서

활동 : 쉬운 방법은

Intent i = new Intent(v.getContext(), SearchList.class); 
i.putExtra("search", search); 

View view = SearchActivityGroup.group.getLocalActivityManager() 
.startActivity("SearchList", i 
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) 
.getDecorView(); 

// Again, replace the view 
SearchActivityGroup.group.replaceView(view); 
ActivityGroup: 

package nl.dante.SuperDeals; 

import java.util.ArrayList; 

import android.app.ActivityGroup; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 

public class SearchActivityGroup extends ActivityGroup { 

View rootView; 

// Keep this in a static variable to make it accessible for all the nested 
// activities, lets them manipulate the view 
public static SearchActivityGroup group; 

// Need to keep track of the history if you want the back-button to work 
// properly, don't use this if your activities requires a lot of memory. 
private ArrayList<View> history; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    /* 
    * this.history = new ArrayList<View>(); group = this; 
    * 
    * // Start the root activity within the group and get its view View 
    * view = getLocalActivityManager().startActivity("Search", new 
    * Intent(this,Search.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) 
    * .getDecorView(); 
    * 
    * // Replace the view of this ActivityGroup replaceView(view); 
    */ 

} 

@Override 
protected void onResume() { 

    super.onResume(); 
    this.history = new ArrayList<View>(); 
    group = this; 

    // Start the root activity within the group and get its view 
    View view = getLocalActivityManager().startActivity("Search", new Intent(this, Search.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); 

    // Replace the view of this ActivityGroup 
    replaceView(view); 
} 

public void replaceView(View v) { 
    // Adds the old one to history 
    if (history.size() == 0) { 
     if (rootView != null) { 
      history.add(rootView); 
      rootView = null; 
     } 
    } 
    history.add(v); 
    // Changes this Groups View to the new View. 
    setContentView(v); 
} 

public void back() { 
    try { 
     if (history.size() > 0) { 
      if (history.size() == 1) { 
       rootView = history.get(0); 
       Toasts.ToastImageView(this, "Druk nogmaals BACK om af te sluiten", R.drawable.power_64_off, "red"); 
      } 
      history.remove(history.size() - 1); 
      setContentView(history.get(history.size() - 1)); 
     } else { 
      finish(); 
     } 
     if (history.size() < 3) { 
      // Tabhost.bannerImage2.setImageResource(0); 
      Tabhost.banner.setBackgroundResource(R.drawable.gradient_blue); 
     } 
     if (history.size() == 2) { 
      Tabhost.bannerImage1.setImageResource(R.drawable.sorteer_btn); 
     } 
    } catch (Exception ex) { 
    } 
} 

public int getHistorySize() { 
    return history.size(); 
} 

@Override 
public void onBackPressed() { 
    try { 
     SearchActivityGroup.group.back(); 
    } catch (Exception ex) { 

    } 
    return; 
} 
} 
+0

이없는

이 내 ActivityGroup의 구현입니다? 왜 새로운 의도가 생기면 탭을 바꿀 수 없습니까? – antumin

관련 문제