重囗另类BBWSeⅹHD,av狼论坛,精品一卡2卡三卡4卡乱码理论,体育生gv老师浪小辉3p警察

android面試題(2)

時間:2024-10-15 04:42:28 學人智庫 我要投稿
  • 相關推薦

android面試題(2)

  Intent intent = new Intent(this,B.class);

android面試題(2)

  intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

  局限性 :所有的activity的啟動模式都要是默認的啟動模式

  講一講你對activity的理解

  把上面的幾點用自己的心得寫出來

  8. service是否在main thread中執行, service里面是否能執行耗時的操作?

  默認情況,如果沒有顯示的指定service所運行的進程, Service和activity是運行在當前app所在進程的main thread(UI主線程)里面

  service里面不能執行耗時的操作(網絡請求,拷貝數據庫,大文件 )

  在子線程中執行 new Thread(){}.start();

  特殊情況 ,可以在清單文件配置 service 執行所在的進程 ,讓service在另外的進程中執行

  9. 兩個Activity之間怎么傳遞數據?

  基本數據類型可以通過. Intent 傳遞數據

  extras.putDouble(key, value)

  intent.putExtra(name, value)

  // 通過intent putExtra 方法 基本數據類型 都傳遞

  Bundle bundle = new Bundle();

  bumdle.putShort(key, value);

  intent.putExtras(bundle);

  intent.putExtras(bundle)

  獲取到激活他的 getIntent();

  Intent intent = getIntent();

  Bundle bundle = intent.getExtras();

  intent.getStringExtra("key","value");

  intent.getBooleanExtra("key","value")

  Application 全局里面存放 對象 ,自己去實現自己的application的這個類,基礎系統的application , 每個activity都可以取到

  讓對象實現 implements Serializable 接口把對象存放到文件上.

  讓類實現Serializable 接口,然后可以通過 ObjectOutputStream //對象輸出流

  File file = new File("c:\\1.obj");

  FileOutputStream fos = new FileOutputStream(file);

  ObjectOutputStream oos = new ObjectOutputStream(fos);

  Student stu = new Student();

  stu.setId("10001");

  stu.setName("zs");

  oos.writeObject(stu);

  FileInputStream fis = new FileInputStream(file);

  ObjectInputStream ois = new ObjectInputStream(fis);

  Student stu1 = (Student) ois.readObject();

  System.out.println(stu1.getName());

  Parcelable 和 Serializable

  Parcelable 把對象序列化到android操作系統 的一塊公用的內存空間

  文件/網絡

  intent.setData(Uri)

  Uri.fromFile(); //大圖片的傳遞

  contentResolver.getInputStream(url);

  10. 怎么讓在啟動一個Activity是就啟動一個service?

  在activity的onCreate()方法里面 startService();

  11. 同一個程序,但不同的Activity是否可以放在不同的Task任務棧中?

  比方說在激活一個新的activity時候, 給intent設置flag

  Intent的flag添加FLAG_ACTIVITY_NEW_TASK

  這個被激活的activity就會在新的task棧里面…

  Intent intent = new Intent(A.this,B.class);

  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

  startActivity(intent);

  12. Activity怎么和service綁定,怎么在activity中啟動自己對應的service?

  startService() 一旦被創建 調用著無關 沒法使用service里面的方法

  bindService () 把service 與調用者綁定 ,如果調用者被銷毀, service會銷毀

  bindService() 我們可以使用service 里面的方法

  bindService(). 讓activity能夠訪問到 service里面的方法

  構建一個intent對象,

  Intent service = new Intent(this,MyService.class);

  通過bindService的方法去啟動一個服務,

  bindService(intent, new MyConn(), BIND_AUTO_CREATE);

  ServiceConnection 對象(重寫onServiceConnected和OnServiceDisconnected方法) 和BIND_AUTO_CREATE.

  private class myconn implements ServiceConnection

  {

  public void onServiceConnected(ComponentName name, IBinder service) {

  // TODO Auto-generated method stub

  //可以通過IBinder的對象 去使用service里面的方法

  }

  public void onServiceDisconnected(ComponentName name) {

  // TODO Auto-generated method stub

  }

  13. 14 .什么是Service以及描述下它的生命周期。Service有哪些啟動方法,有什么區別,怎樣停用Service?

  在Service的生命周期中,被回調的方法比Activity少一些,只有onCreate, onStart, onDestroy,

  onBind和onUnbind。

  通常有兩種方式啟動一個Service,他們對Service生命周期的影響是不一樣的。

  1 通過startService

  Service會經歷 onCreate 到onStart,然后處于運行狀態,stopService的時候調用onDestroy方法。

  如果是調用者自己直接退出而沒有調用stopService的話,Service會一直在后臺運行。

  2 通過bindService

  Service會運行onCreate,然后是調用onBind, 這個時候調用者和Service綁定在一起。調用者退出了,Srevice就會調用onUnbind->onDestroyed方法。

  所謂綁定在一起就共存亡了。調用者也可以通過調用unbindService方法來停止服務,這時候Srevice就會調用onUnbind->onDestroyed方法。

【android面試題(2)】相關文章:

android面試題目09-08

Android工程師的面試題08-07

Android工程師面試題10-24

關于Android工程師面試題09-19

德國公司經典面試題(2)07-10

Microsoft面試題09-04

iOS面試題07-10

公司面試題09-12

hibernate面試題10-18

英語面試題精選06-13

主站蜘蛛池模板: 玛纳斯县| 旅游| 双柏县| 新化县| 深泽县| 封丘县| 曲水县| 衡阳县| 从江县| 拜城县| 邢台县| 中阳县| 七台河市| 于都县| 松滋市| 耒阳市| 阿鲁科尔沁旗| 黄浦区| 浦东新区| 舒城县| 奉贤区| 汉沽区| 伽师县| 南丹县| 郓城县| 金寨县| 吉木萨尔县| 库车县| 于都县| 连山| 林周县| 永定县| 辽中县| 麻江县| 扶余县| 连南| 田东县| 垣曲县| 瑞丽市| 罗源县| 格尔木市|