真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android兼容之?dāng)z像頭權(quán)限關(guān)閉后應(yīng)用生命周期和單例數(shù)據(jù)變化-創(chuàng)新互聯(lián)

攝像頭權(quán)限關(guān)閉后異常

描述:當(dāng)app攝像頭權(quán)限打開后,運(yùn)行中的app和單例中的數(shù)據(jù)正常;切換到設(shè)置頁面關(guān)閉攝像頭權(quán)限后;再切換到app發(fā)生的變化
結(jié)果: activity會(huì)重新繪制,activity歷史棧會(huì)保留,但是回退到歷史棧的activity會(huì)重新從onCreate(***)開始;且單例中的數(shù)據(jù)被重置,例如:int 數(shù)據(jù)被重置為0,對(duì)象被重置為null

創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,提供網(wǎng)站制作、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);可快速的進(jìn)行網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,是專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!示例:

單例代碼

public class CountManager {private CountManager() {}

    public static CountManager getInstance() {return SingleHolder.instance;
    }

    private static class SingleHolder {private static final CountManager instance = new CountManager();
    }

    private int mCount = 0;

    public void addCount() {mCount++;
    }

    public int getCount() {return mCount;
    }
}

第一個(gè)activity

public class MainActivity extends AppCompatActivity {private static final String TAG = "MainActivity-1";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        CountManager.getInstance().addCount(); //單例中數(shù)據(jù)增加
        findViewById(R.id.btn_second_click).setOnClickListener(new View.OnClickListener() {@Override
            public void onClick(View v) {startActivity(new Intent(MainActivity.this, SecondActivity.class));
            }
        });
        Log.d(TAG, "onCreate: ");
    }

    @Override
    protected void onResume() {super.onResume();
        Log.d(TAG, "onResume: " + CountManager.getInstance().getCount());
    }

    @Override
    protected void onPause() {super.onPause();
        Log.d(TAG, "onPause: ");
    }

    @Override
    protected void onDestroy() {super.onDestroy();
        Log.d(TAG, "onDestroy: ");
    }
}

第二個(gè)activity

public class SecondActivity extends AppCompatActivity {private static final String TAG = "MainActivity-Second";

    @Override
    protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        CountManager.getInstance().addCount();
         if (savedInstanceState == null) {getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, MainFragment.newInstance())
                    .commitNow();
        }
        Log.d(TAG, "onCreate: ");
    }

    @Override
    protected void onResume() {super.onResume();
        Log.d(TAG, "onResume: "+ CountManager.getInstance().getCount());
    }

    @Override
    protected void onPause() {super.onPause();
        Log.d(TAG, "onPause: ");
    }

    @Override
    protected void onStop() {super.onStop();
        Log.d(TAG, "onStop: ");
    }

    @Override
    protected void onDestroy() {super.onDestroy();
        Log.d(TAG, "onDestroy: ");
    }
}

備注:記得app增加攝像頭權(quán)限

運(yùn)行結(jié)果

1、啟動(dòng)app后,在MainActivity,點(diǎn)擊跳轉(zhuǎn)到SecondActivity

D  onCreate: 
15:28:09.177 com.xiaoma.testc                     D  onResume: 1

15:28:11.663 com.xiaoma.testc                     D  onPause: 
15:28:11.708 com.xiaoma.testc                     D  onCreate: 
15:28:11.751 com.xiaoma.testc                     D  onResume: 2

2、切換到桌面,攝像頭權(quán)限進(jìn)行關(guān)閉操作或者打開后再關(guān)閉

15:31:44.956 com.xiaoma.testc                     D  onPause: 
15:31:44.989 com.xiaoma.testc                     D  onStop: 
---------------------------- PROCESS ENDED (31143) for package com.xiaoma.testc ----------------------------

可以看到進(jìn)程關(guān)閉了的信息
3、再次點(diǎn)擊app,查看里面的數(shù)據(jù),然后進(jìn)行回退歷史棧

---------------------------- PROCESS STARTED (32348) for package com.xiaoma.testc ----------------------------
15:32:57.135 com.xiaoma.testc                     D  onCreate: 
15:32:57.170 com.xiaoma.testc                     D  onResume: 1
15:33:13.688 com.xiaoma.testc                     D  onPause: 
//返回操作后
15:33:13.751 com.xiaoma.testc                     D  onCreate: 
15:33:13.755 com.xiaoma.testc                     D  onResume: 2
15:33:14.162 com.xiaoma.testc                     D  onStop: 
15:33:14.167 com.xiaoma.testc                     D  onDestroy:

可以看到重啟啟動(dòng)了進(jìn)程,且歷史棧存在

總結(jié)

對(duì)于開發(fā)SDK的,由于需要宿主傳遞接口回調(diào),會(huì)導(dǎo)致回調(diào)為null,所以在頁面需要進(jìn)行回調(diào)判斷,進(jìn)行相關(guān)的業(yè)務(wù)處理。

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧


分享文章:Android兼容之?dāng)z像頭權(quán)限關(guān)閉后應(yīng)用生命周期和單例數(shù)據(jù)變化-創(chuàng)新互聯(lián)
瀏覽路徑:http://weahome.cn/article/djoegc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部