程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> activityÆô¶¯·½Ê½¿ÉÄÜ´øÀ´µÄһЩbug

activityÆô¶¯·½Ê½¿ÉÄÜ´øÀ´µÄһЩbug

編輯:C++入門知識

activityÆô¶¯·½Ê½¿ÉÄÜ´øÀ´µÄһЩbug


ÔÚ×öÏîÄ¿µÄʱºò£¬Í»È»Åöµ½¼¸¸ö½çÃæµÄÀ´»ØÌøת֮ºó£¬¹Ø±Õactivity£¬ÒªÃ´³öÏÖÖظ´£¬ÒªÃ´½çÃæ¹Ø±Õ²»ÁË£¨°´back¼üÖ»ÊÇÍ˳öÒ»¸öÌض¨µÄactivity£©¡£³öÏÖÕâÑùµÄÇé¿ö¾ÍÒª¿¼ÂÇactivityµÄÆô¶¯·½Ê½ÁË¡£

1¡¢activityµÄÆô¶¯·½Ê½×ܽá

(1)standard

android×Ü»áΪĿ±êactivity´´½¨Ò»¸öеÄʵÀý£¬²¢°ÑactivityÌí¼Óµ½µ±Ç°TaskÖУ¬¼´²»»áÆô¶¯ÐµÄTASK,еÄactivity»áÌí¼Óµ½Ô­ÓеÄTaskÖС££¨hashcode²»Í¬£¬TSAKidÏàͬ£©

£¨2£©singletop

¸´ÓÃTaskÕ»¶¥ActivityʵÀý£¬ÆäÓàÓëstandard·½Ê½Ïàͬ¡£

£¨3£©singleTask

ÔÚͬһ¸öTaskÖÐÖ»ÓÐÒ»¸öacyivityʵÀý¡££¨Èô¸ÃʵÀý´æÔÚÇÒ²»ÔÙÕ»¶¥£¬Ôò»áÒƳýËüÇ°ÃæËùÓеÄactivityʵÀý£©

£¨4£©singleInstance£¨ÓõĶࣩ

ϵͳ±£Ö¤ÎÞÂÛ´ÓÄǸöTaskÆô¶¯Ä¿±êactivity£¬Ö»»á´´½¨Ò»¸öÄ¿±êactivityʵÀý£¬²¢Ê¹ÓÃÒ»¸öȫеÄTASKÀ´¼ÓÔظÃʵÀý¡£

1£©Èô²»´æÔÚ¸ÃÄ¿±êactivityÔò´´½¨Ò»¸öȫеÄTASK¡£ÔڰѸÃÄ¿±êʵÀý¼ÓÈëTASKÕ»¶¥¡£

2£©Èô´æÔÚ¸ÃÄ¿±êactivity£¬ÏµÍ³»á²»¹ËÒ»ÇаÑËûËùÔÚµÄTASKתµ½Ç°Ì¨ÏÔʾ³öÀ´¡£


2¡¢Ê¹ÓÃstartActivity·½·¨Æô¶¯µÄactivity½çÃæÒª¿¼ÂÇactivityµÄTASK¹ÜÀí·½Ê½¡£ÔÚÇåµ¥ÎļþÖÐÅäÖÃactivityµÄÆô¶¯Ä£Ê½£¬±ÜÃâ³öÏÖbug£¬¹Ø±Õ²»ÁË£¬»òÊÇÖظ´½çÃæµÄ³öÏÖ¡£


3¡¢ÊµÏÖÔÚÒ»¸öactivityÖйرÕÁíÍâÒ»¸öactivity

£¨1£©ÔÚµÚÒ»¸öactivityÖÐÓÃÒ»¸ö¾²Ì¬·Ç˽ÓÐ×Ö¶ÎÀ´±£´æ¸ÃÀàµÄʵÀý¡£È»ºóÔÚÁíÍâÒ»¸öactivity ÖлñµÃ¸Ã×ֶβ¢µ÷ÓÃfinish·½·¨£¬Íê³É¸Ã²Ù×÷¡£

£¨2£©¾ßÌå´úÂëÈçÏ£º

public class OneActivity extends Activity {
	 static OneActivity instance;//¹Ø¼ü
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_one);
        instance=OneActivity.this;//¹Ø¼ü
        Log.i("OneActivity", "onCreate");
    }
    
    public void start(View v){
    	startActivity(new Intent(OneActivity.this,TwoActivity.class));
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.one, menu);
        return true;
    }
    @Override
    protected void onDestroy() {
    	Log.i("OneActivity", "µÚÒ»¸öactivity¹Ø±Õ");
    	super.onDestroy();
    }
    
}


public class TwoActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        Log.i("TwoActivity", "onCreate");
    }

    public void back(View v){
    	startActivity(new Intent(TwoActivity.this,OneActivity.class));
    	
    }
    public void  myStop(View v){
    	
    	OneActivity.instance.finish();
    }
  
    @Override
    protected void onDestroy() {
    	// TODO Auto-generated method stub
    	super.onDestroy();
    	 Log.i("TwoActivity", " onDestroy()");
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.one, menu);
        return true;
    }
    
}

ÓÃ
startActivityÀ´»ØÌøתµÄ½á¹û²¢°´back¼üÏú»ÙÈçÏÂËùʾ£º

\

ÏÈÌøתµ½µÚ2¸öactivity£¬ÔÚµÚ2¸öactivityÀïÏú»ÙµÚÒ»¸öactivityʵÀý£¬ÔÚbackÍ˳öÓ¦Óýá¹û£º<†·Ÿ"http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20141201/2014120109193739.png" alt="">

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved