简体   繁体   English

android 1.6,后退按钮和onActivityResult

[英]android 1.6, back button and onActivityResult

I'm working on a project with android 1.6 as target. 我正在开发一个以android 1.6为目标的项目。

So, I can't use 所以,我不能用

@Override public void onBackPressed(){...}

I'm starting an activity with 我正在开展一项活动

startActivityForResult(intent,requestcode)

And I wan't to get back some info with 我不想回复一些信息

@Override protected void onActivityResult (int requestCode, int resultCode, Intent data) 

the problem is the following: 问题如下:

-'Activity A' throws 'Activity B' -'Activity A'抛出'活动B'

-during 'ActivityB' the hardware back button is pressed - 在'ActivityB'中按下硬件后退按钮

-'Activity A's onActivityResult is called but I don't get any info in data (data==null) -'Activity A的onActivityResult被调用,但我没有获得任何数据信息(data == null)

I'm trying to put some extra info at 'Activity B's 我试图在'活动B'中添加一些额外的信息

@Override protected void onPause(){...}

I also call setResult(RESULT_OK,i); 我也叫setResult(RESULT_OK,i); into this onPause but I always get RESULT_CANCELED and data==null at 'Activity A's onActivityResult 进入这个onPause,但我总是得到RESULT_CANCELED和数据== null在'活动A的onActivityResult

Instead of onBackPressed you can use: 您可以使用以下命令代替onBackPressed:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        //set result and finish()

    } else { 
        return super.onKeyDown(keyCode, event);
    }
}

I don't see the values of the constants you pass to and fro. 我没有看到你来回传递的常数的值。 And they are important. 它们很重要。

Here are some pieces of my working code that calls an activity for result: 以下是我调用结果活动的一些工作代码:

------------------------------------- PackVideo activity -------------------------------------- ------------------------------------- PackVideo活动----------- ---------------------------

calling for ServerSetActivity 调用ServerSetActivity

Intent serverSetIntent = new Intent();
serverSetIntent.setClass(this, ServerSetActivity.class);
startActivityForResult(serverSetIntent, CHANGE_IP);

constants setting and result catching: 常量设置和结果捕获:
(I have them together, because only here in catching both costants meet) (我把它们放在一起,因为只有这里才能抓住两个costants相遇)

static public int CHANGE_IP = 1000;
static public int CHANGE_IP_DONE = 1001;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // If the request was for CHANGE_IP and the request was CHANGE_IP
    if (resultCode == CHANGE_IP_DONE && requestCode == CHANGE_IP) {
        readBaseInfoFromServer(getApplicationContext());
        startVideoPlayerService(getApplicationContext());
        setCurrentChannelAndPlay(getApplicationContext(), 0);
    }
}

----------------------------------- ServerSetActivity ---------------------------------------- ----------------------------------- ServerSetActivity -------------- --------------------------

ending of the called activity 被叫活动的结束

final Intent intent = new Intent();
setResult(PackVideo.CHANGE_IP_DONE, intent);
finish();
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // check if the request code is same as what is passed  here it is 2
        if (resultCode != RESULT_OK) {
            if (requestCode == 2 && data != null) {
//DO YOUR  OVER HERE}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 1.6:未调用onActivityResult - Android 1.6: onActivityResult is not called 后退按钮未调用onActivityResult - onActivityResult not called on back button Android-OnActivityResult按钮单击 - Android - OnActivityResult Button Click onActivityResult不是在屏幕上按下向后箭头时调用,而是仅在android中按下向后按钮时调用? - onActivityResult not called when pressed back arrow on screen but only called when back button pressed in android? 单击ActionBar中的后退按钮时,不会调用onActivityResult - onActivityResult is not called when the back button in ActionBar is clicked Android - startActivityForResult onActivityResult 返回 ArrayList - Android - startActivityForResult onActivityResult get ArrayList back 无法在Android中的Actvity中获得回叫onActivityResult的调用 - Unable to get call Back onActivityResult in Actvity in android Android从onActivityResult接收值并将其设置为Button - Android receive value from onActivityResult and set it to a Button Android登录按钮不调用onActivityResult或回调方法 - Android Login button not calling onActivityResult or callback methods 卡在图像捕获屏幕上,无法返回onActivityResult(Android) - stuck on image capture screen ,can't get back to onActivityResult (Android)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM