Bonjour ,

(Android : Platform :2.1,Api level :7)

- j'ai Tab Host de 2 group (Group1 et Group2)

ce qui m'intéresse le group1 :
Group1: activity 1(next) ---> activity 2(button cam)--> itent camera
Si je fais back (bouton) --> toujours activity 2 --> pas de problème
mais si je prend une image --> le programme de me demande enregistrer ou pas enregistrer )-->j'appuyer sur enregistrer -->
donc ici je me trouve sur activity 1 mais normalement je dois rester sur activity 2 !!!

Pourquoi il ne reste pas dans activity 2 ???

Merci d'avance

Code Source :

TabeSimple (2 group):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
public class TabSample extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        TabHost tabHost = getTabHost();       
 
      tabHost.addTab(tabHost.newTabSpec("tab1")
              .setIndicator("Group 1")
              .setContent(new Intent(this, TabGroup1Activity.class)));
 
      tabHost.addTab(tabHost.newTabSpec("tab2")
              .setIndicator("Group 2")
              .setContent(new Intent(this, TabGroup2Activity.class)));
 
      tabHost.setCurrentTab(1); 
    }
}
Group 1:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
public class TabGroup1Activity extends TabGroupActivity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("OptionsActivity", new Intent(this,OptionsActivity.class));
    }
}
Group2:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
public class TabGroup2Activity extends TabGroupActivity {
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("EditActivity", new Intent(this,EditActivity.class));
    }
}
Activity 1:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class OptionsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.optionspage);
 
        Button back = (Button) findViewById(R.id.BackButton1);
        Button next = (Button) findViewById(R.id.NextButton1);
 
        OnTouchListener backListener = new OnTouchListener() {
                public boolean  onTouch  (View  v, MotionEvent  event) {
                    if (event.getAction()==MotionEvent.ACTION_UP){
                        finish();
                        //return true;
                    }
                    return false;
                }
            };
 
        OnTouchListener nextListener = new OnTouchListener() {
        	public boolean onTouch(View v, MotionEvent event) {
        		 if (event.getAction()==MotionEvent.ACTION_UP){
        			 Intent edit = new Intent(getParent(), cam.class);
             		TabGroupActivity parentActivity = (TabGroupActivity)getParent();
             		parentActivity.startChildActivity("cam", edit);
             		return true;
        		 }
        		 return false;
        	}
        };
 
        back.setOnTouchListener(backListener);
        next.setOnTouchListener(nextListener);
    }
}
activity 2 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class cam extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.camera);
 
        Button cam = (Button) findViewById(R.id.camera);
 
        cam.setOnClickListener(new OnClickListener() 
        {
        @Override
        public void onClick(View arg0) 
        {
        Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    	getParent().startActivityForResult(camera, 0); 
 
 
 
        }});
    }
}

Parent activity:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
public class TabGroupActivity extends ActivityGroup {
 
    private ArrayList<String> mIdList;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);       
        if (mIdList == null) mIdList = new ArrayList<String>();
    }
 
    /**
     * This is called when a child activity of this one calls its finish method. 
     * This implementation calls {@link LocalActivityManager#destroyActivity} on the child activity
     * and starts the previous activity.
     * If the last child activity just called finish(),this activity (the parent),
     * calls finish to finish the entire group.
     */
  @Override
  public void finishFromChild(Activity child) {
      LocalActivityManager manager = getLocalActivityManager();
      int index = mIdList.size()-1;
 
      if (index < 1) {
          finish();
          return;
      }
 
      manager.destroyActivity(mIdList.get(index), true);
      mIdList.remove(index); index--;
      String lastId = mIdList.get(index);
      Intent lastIntent = manager.getActivity(lastId).getIntent();
      Window newWindow = manager.startActivity(lastId, lastIntent); 
      setContentView(newWindow.getDecorView());
  }
 
  /** 
   * Starts an Activity as a child Activity to this.
   * @param Id Unique identifier of the activity to be started.
   * @param intent The Intent describing the activity to be started.
   * @throws android.content.ActivityNotFoundException.
   */
  public void startChildActivity(String Id, Intent intent) {     
      Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
      if (window != null) {
          mIdList.add(Id);
          setContentView(window.getDecorView()); 
      }    
  }
 
  /**
   * The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
   * from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
   */
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
          return true;
      }
      return super.onKeyDown(keyCode, event);
  }
 
  /**
   * Overrides the default implementation for KeyEvent.KEYCODE_BACK 
   * so that all systems call onBackPressed().
   */
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          onBackPressed();
          return true;
      }
      return super.onKeyUp(keyCode, event);
  }
 
  /**
   * If a Child Activity handles KeyEvent.KEYCODE_BACK.
   * Simply override and add this method.
   */
  @Override
  public void  onBackPressed  () {
      int length = mIdList.size(); 
      if ( length > 1) {
          Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
          current.finish();
      }  
  }
}