在Android的儿童活动 [英] Child Activity in Android

查看:105
本文介绍了在Android的儿童活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有两个活动。主要的被称为主要,和孩子一个叫儿童。当点击的主要活动一个按钮,它触发了下面这段code:

So I have two Activities. The main is called Main, and the child one is called Child. When a button is clicked in the main activity it triggers the following piece of code:

Intent i = new Intent(Main.this, Child.class);
Main.this.startActivity(i);

在打开的儿童活动。

当我打电话完成()或preSS后退按钮的子活动中,而不是回到主要的一个,应用程序只是关闭。你能不能给我一个提示,其中的问题可能是:(

As soon as I call finish() or press the back button within the child activity instead of going back to the main one, the app just closes. Can you give me a hint where the problem might be :(

PS 的试错我发现,如果编辑的的Andr​​oidManifest.xml 的添加

P.S. By trial and error I found out that if edit AndroidManifest.xml and add

android:theme="@android:style/Theme.Dialog"

儿童后退按钮的声明,并呼吁在完成()行为与预期:关闭子活动,并带来了主要的成为关注的焦点。问题是,当我开始打字的的EditText 屏幕开始闪动(相当的bizzare)。所以我不能用它作为一个对话框。我的主要活动使用的相机,这样可能会犯的问题。虽然当子活动开始,在的onPause 事件被触发,停止摄像机,直到 onResume 被调用。

within the declaration of Child the back button and calling finish() behaves as expected: closes the child activity and brings the main into focus. The problem is that when I start typing in an EditText the screen starts flickering (rather bizzare). So I can't use it as a dialog. My main activity uses the camera, so that might be making problems. Although when the child activity is started, the onPause event is fired and it stops the camera until onResume is called.

编辑:

所以我试图用 startActivityForResult 并添加

Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();

的onPause 和一个类似的 onResume 的方法。当孩子返回 onResume 不被触发。我甚至overrided onActivityResult ,甚至不会被触发。 :(那么离奇...

to the onPause and a similar one to the onResume methods. When the Child returns onResume doesn't get triggered. I even overrided onActivityResult and even that doesn't get triggered. :( So bizarre...

我想我找到了问题,但我解决不了它自己

儿童活动被激活,的onStop ,然后紧接着又的onDestroy 主要活动中被调用。但是,为什么?!?

When the Child activity is activated, onStop and immediately after that onDestroy are invoked within the Main activity. But why?!?

推荐答案

您应该能够做到以下几点:

You should be able to do the following:

Intent i = new Intent(this, Child.class);
startActivityForResult(i);

(你只需要Main.this如果你是从内部类调用此)。

(You only need Main.this if you are invoking this from an inner class).

当你想退出子活动:

setResult(Result.OK);
finish();

这应该引起onActivityResult在主类中调用,随后OnResume。

This should cause onActivityResult to be invoked in your Main class, followed by OnResume.

如果不工作,你可以尝试把破发点,或打印语句中的各种ONX方法,看看这些被调用。

If that doesn't work, you might try putting break points or print statements in the various onX methods, to see which are being called.

这篇关于在Android的儿童活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆