当按下后退按钮时,我们如何回溯活动?即从堆栈中弹出活动

时间:2018-11-05 17:17:53

标签: android android-activity back-stack

简单来说,当在活动'A'之后堆叠活动'B'时,想要活动'A'在活动'B'中按下后退按钮的同时恢复。不想让活动“ A”使用intent重新启动,而是希望恢复活动“ A”。

2 个答案:

答案 0 :(得分:0)

您可以使用各种启动模式标志来影响此行为。请参阅有关此主题的官方文档:

https://developer.android.com/guide/components/activities/tasks-and-back-stack

答案 1 :(得分:0)

您可以覆盖onSaveInstanceState(Bundle savedInstanceState)并编写要保存为Bundle参数的应用程序状态值,如下所示:

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);
  // Restore UI state from the savedInstanceState.
  // This bundle has also been passed to onCreate.

  int x = savedInstanceState.getInt("X");
  String y = savedInstanceState.getString("Y");
}

该捆绑包将传递给onCreate()以及onRestoreInstanceState(),您将在其中提取像这样的值:

var bitcore = require('node_modules/bitcore-explorers/node_modules/bitcore-lib');
var Insight = require("node_modules/bitcore-explorers").Insight;
var insight = new Insight("testnet");

function getUtxos(address){
    return new Promise((resolve, reject)=>{
        insight.getUnspentUtxos(address, (err, utxos)=>{
            if(err) reject(err)
            else{
                resolve(utxos);
            }
        })
    })
}

async function sendingBtc() {
    console.log(req.body)
    let utxos = await getUtxos(address);
    // Another function to derive your private key 
    let privateKey = await generatePrivKey 
    bitcore.Transaction()
        .from(utxos)
        .to(req.body.txSendAddress,amount*100000000 - 3000)
        .change(changeAddress)
        .sign(privateKey);
    insight.broadcast(tx, (err, returnedTxId)=>{
        if(!err) console.log(returnedTxId)
    })