Android activity for kids

So, I have two operations. The main one is called the Main , and the child is called the Child . When the button is pressed in the main action, it calls the following code fragment:

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

This opens up the activity of the child .

As soon as I call the finish line () or click the "Back" button in the child activity, and do not return to the main one, the application will simply close. Can you give me a hint where the problem might arise :(

PS By court and by mistake I found out that if you edit AndroidManifest.xml and add

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

in the childโ€™s button declaration, and the finish () call behaves as expected: closes the child activity and focuses the main attention. The problem is that when I start typing EditText , the screen starts to flicker (rather, bizzare). Therefore, I cannot use it as a dialogue. My main activity is using a camera, so this can cause problems. Although, when a child activity starts, the onPause event fires and stops the camera until onResume is called.

Edit:

So I tried using startActivityForResult and added

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

for onPause and a similar onResume method. When Child returns onResume , it does not start. I even redefined onActivityResult , and even that doesn't work. :( So weird ...

I think I found a problem, but I canโ€™t solve it myself

When the Child operation is active, onStop and immediately after that onDestroy is called as part of the Main activity, But why?!?

+7
java android android-activity android-manifest
source share
3 answers

You should be able to do the following:

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

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

If you want to exit child activity:

 setResult(Result.OK); finish(); 

This should call onActivityResult to call in your main class, followed by OnResume.

If this does not work, you can try to set breakpoints or print instructions in various onX methods to see which calls are being made.

+10
source share

According to http://developer.android.com/resources/faq/commontasks.html#opennewscreen , which happens when you start a new activity, itโ€™s really different:
If the first action is still visible in some way (as you discovered, if it is shown as a dialog, for example), it will simply receive onPause() ; if it is no longer visible, it will also receive onStop() .
But, as another said, if you run the second action to get the results, startActivityForResults seems more logical

(I am also a beginner and learn formatting, you can read the help by clicking on the orange question mark - use 4 spaces in front of the code samples to indent them, apparently)

+1
source share

I used Dialog instead of Activity, and everything worked fine, so I leave it that way.

0
source share

All Articles