2015-11-25 65 views
0

我在主要活動增加了一個onDestroy次活動禁用藍牙適配器

@Override 

protected void onDestroy() { 

     if (BTAdapter.isEnabled()) { 
      BTAdapter.disable(); 
     } 

     this.unregisterReceiver(receiver); 
     super.onDestroy(); 
    } 

在我的主要活動我從抽屜式導航

if (id == R.id.nav_devices) { 

      intent = new Intent("com.navigationwithrssi.RSSIActivity"); 
      startActivity(intent); 
} 

啓動另一個活動,但是當我回來我的主要活動(使用工具欄中的默認後退按鈕),RSSIActivity會自動禁用藍牙適配器。

我只是想讓我的主要活動能夠做到這一點,有沒有辦法做到這一點?

回答

0

我解決了我的問題。它實際上是很容易的,在教程的提供高達通航developer.android.com

我只是把這個代碼在我onOptionsItemSelected方法

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
    // Respond to the action bar's Up/Home button 
    case android.R.id.home: 
     NavUtils.navigateUpFromSameTask(this); 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

而且我做了我父活動的啓動模式<singleTop>

android:launchMode="singleTop" 

它所做的是,而不是創建父活動的一個新實例,它只是將其帶到堆棧的頂部。