子活动禁用蓝牙适配器

时间:2015-11-25 06:11:13

标签: android bluetooth

我在主要活动

中添加了reff
#include <iostream>

class Reff
{
public:
    int a;
    float b; // changed the data type to illustrate overloading the = operator

    // operator= will be called if we try to assign to a an object of this class;
    // this version of the function accepts an integer value
    Reff& operator= (int intval)
    {
            a = intval;
            return *this;
    }

    // another operator=, this one accepting a float value as the parameter
    Reff& operator= (float floatval)
    {
            b = floatval;
            return *this;
    }
};

// operator+ will be called if we try to add a value to this object;
// I'm only defining this one which accepts an int value
int operator+ (Reff const& reff, int intval)
{
    return reff.a + intval;
}

// an overload of the operator<< function, which accepts a reference to
// an instance of a Reff, along with the output stream parameter.
std::ostream& operator<< (std::ostream& stream, Reff const& reff)
{
    return stream << "[a:" << reff.a << " b:" << reff.b << "]";
}


int main()
{
    // create an instance of our class
    Reff per;

    // assign the instance 42 (an integer value) - this will use the integer
    // overload of the operator= we defined
    per = 42;

    // assign it a floating point value - this will use the float overload
    // of the operator=. Note that if we didn't define a float-specific overload,
    // the compiler would probably truncate the value to an integer and use our
    // integer version instead - possibly with a warning, possibly silently,
    // depending on your compiler settings.
    per = 3.14159f;

    // output the object; this will use the overload of the operator<< function
    // that we created, which accepts our Reff object
    std::cout << per << std::endl;

    // output the result of adding 58 to our object; this will use the operator+
    // overload which accepts an integer
    std::cout << "per + 58 = " << (per + 58) << std::endl;
}

在我的主要活动中,我通过导航抽屉开始另一项活动

onDestroy

但是当我回到主要活动(使用工具栏中的默认后退按钮)时,RSSIActivity会自动禁用蓝牙适配器。

我只是希望我的主要活动能够做到这一点,有没有办法做到这一点?

1 个答案:

答案 0 :(得分: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"

它所做的不是创建父活动的新实例,而是将其带到堆栈顶部。