Re: [android-developers] Re: Android finishActivity()
Hello Mike, I somehow missed your last email. On Wed, Jun 16, 2010 at 5:16 AM, mike wrote: > Hi Sean, > > i hope you also has gone out of answers. any way kindly let me know > this. > > A --> B --> C --> C --> where? C to A? C to finished? C to force close dialog? What I'm looking for is a visual flow of the activities, what isn't clear is what is supposed to happen once you start hitting the back button. > > if i'm going to start Activity C from Activity B like this > > startActivity(Activity C); > > and when i press back button from activity C > > �...@override > public boolean onKeyDown(int keyCode, KeyEvent event) { > // TODO Auto-generated method stub > if (keyCode == KeyEvent.KEYCODE_BACK) { > finish(); > return true; > } > return false; > } > > since i have call finish() method application will redirect back to > Activity B > > so once i'm redirected to Activity B is there a way to capture that > i'v been back to Activity B > Yes, this is the purpose of startActivityForResult() and onActivityResult(). > because onCreate method will not fire up like that how can i capture > it. then i'll be bale to finish() the activity You are still trying to fudge your existing code to work. You need to take this back to the design stage and work out exactly what it is you want to do. Saying things like: > i want Activity C to run on top of Activity B. Indicates that you require both activities to be open and communicating with each other simultaneously, this is not a sensible approach as Activity B could disappear at any time for a variety of reasons. Re-think your approach in terms of a website. You don't have "index.html" and "basket.html" open at the same time, you communicate between them using a combination of the HTTP request-response pattern (in Android terms: startActivityforResult-onActivityResult), and storage solutions such as databases and user sessions (in Android terms: content providers and extending android.app.Application). Decouple your dependencies between activities, and this will become a lot easier. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android finishActivity()
OK I must have misinterpreted your description, so you want: A -> B -> C -> B -> (close) The simple answer is to move the android:noHistory="true" from the Activity B declaration, to the Activity A one. On Sat, Jun 5, 2010 at 3:25 PM, mike wrote: > Hi Sean, > > when you set > ... activity> > like this what happens is > > Activity C runs on top of Activity A not on Activity B. > > that is not what i want i want Activity C to run on top of Activity B > > regards, > Mike > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android finishActivity()
OK Mike, so reading carefully through your explanation, it looks to me that the process you want is this: A -> B -> C -> A -> (app close) Whilst what you are actually getting, with your current code, is this: A -> B -> C -> A -> A -> B -> (unknown) The complex nature of your activity jumping suggests that the code is simply too complex. I suggest you replace all the onKeyDown() and startActivityForResult() handling for something like this: Activity A // This code goes in the correct method of Activity A to start Activity B startActivity(new Intent(ActivityA, ActivityB)); Activity B // This code goes in the correct method of Activity B to start Activity C startActivity(new Intent(ActivityB, ActivityC)); // Set the "noHistory" attribute for Activity B in your AndroidManifest.xml ... Activity C // This code goes in the correct method of Activity C to jump back to Activity A finish(); The outcome should be the navigation you are looking for. Activity B is skipped when you press the back button from Activity C. Pressing the back button again will close the application. Cheers, Sean On Fri, Jun 4, 2010 at 1:03 PM, mike wrote: > hi Sean, > > this is what i have done. > > i Have 3 activities. Activity A, Activity B, and Activity C. > > Activity A is the starting Activity. > > according to a user action Activity A will navigate to Activity B like > this. > finish(); > startActivityForResult(Activity B, 102); > > Activity A --> Activity B > > after 5 seconds Activity B will starts Activity C > > StartActivity(Activity C) > > and will not finish Activity B. > > on top of Activity B, Activity C will be run. > > this is Activity C onCreate method > > �...@override > protected void onCreate(Bundle savedInstanceState) { > // TODO Auto-generated method stub > super.onCreate(savedInstanceState); > Bundle b = getIntent().getExtras(); > msg_id = b.getLong("ID"); > > getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, > > WindowManager.LayoutParams.FLAG_BLUR_BEHIND); > setContentView(R.layout.blur_blue); > } > > this is manifest.xml > > > > this is my theme.xml > > > > #77ff > #7700ff00 > #70970468 > #70de6496 > #7f00 > #70ff7e00 > #70fff000 > > > so Activity C will run on top of Activity B. > > so when i pressed back button from activity C > > application should redirects to Activity A. > > �...@override > public boolean onKeyDown(int keyCode, KeyEvent event) { > // TODO Auto-generated method stub > if (keyCode == KeyEvent.KEYCODE_BACK) { > finish(); > finishActivity(102); > startActivity(new Intent(Acitivyt C, Activity > A )); > return true; > } > return false; > } > > Application redirects to Activity A and when i pressed back from > Activity A > > again it redirects to Activity B and will not close the application. > > this is what i'm doing in Activity A > > �...@override > public boolean onKeyDown(int keyCode, KeyEvent event) { > // TODO Auto-generated method stub > boolean b = false; > if (keyCode == KeyEvent.KEYCODE_BACK) { > // int x = android.os.Process.SIGNAL_QUIT; > finish(); > finishActivity(102); > } > return b; > } > > so Sean what do you think?? what can be done. > > regards, > Mike > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android finishActivity()
Mike, You need to think of activities like a stack of cards. If you open one, it will be placed on top of the pack. So if you want to open a new activity from Activity B, just do use startActivity() as normal. Activity A ---> Activity B --> Activity C When you close Activity C, do a setResult(RESULT_CANCELLED) followed by finish() just like I described for Activity B. Activity B will handle the onActivityResult(), where you tell it to do the same thing again. This way you are popping the activities off the stack one-by-one, when there are no more activities left, the app will close. To the user, this will appear as though Activity A and Activity B had been closed when Activity C opened. Your second option, which I did not think of before, is to add the android:noHistory="true" attribute to Activity A and Activity B in your AndroidManifest.xml. I don't have much experience with this flag, but my understanding is that it will close the current activity when another one is opened. The first approach will give you more control, but this attribute might be simpler: http://developer.android.com/intl/fr/guide/topics/manifest/activity-element.html#nohist If I'm on the wrong track here, perhaps you could describe what you want step-by-step. At the moment, it sounds like you want the stack to have just one activity at all times. Cheers, Sean On Fri, Jun 4, 2010 at 9:52 AM, mike wrote: > hi Sean Hodges, > > it's working correctly. and is there a way to achieve this thing using > startActivity()??? > > Starting Activity B like this > > startActivity(intent); > > so when i press back button from Activity B i'm doing this > > �...@override > public boolean onKeyDown(int keyCode, KeyEvent event) { > // TODO Auto-generated method stub > if (keyCode == KeyEvent.KEYCODE_BACK) { > finish(); > return true; > } > return false; > } > > and i don't want to redirect to the Activity A. i just want to send it > to another activity. is this possible??? > > regards, > Mike > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android finishActivity()
Mike, You've done half the work already, except there is a little confusion on the purpose of the finishActivity() method. That method only works the other way around (closing Activity B from Activity A). What you need to do now is send a "result" back to Activity A telling it to call finish(). See the "Returning a Result from a Screen" section here: http://developer.android.com/intl/fr/guide/appendix/faq/commontasks.html#opennewscreen In Activity B, you simple want to do: if (keyCode == KeyEvent.KEYCODE_BACK) { setResult(RESULT_CANCELED); finish(); } and in Activity A, you want to handle the result callback: protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_CANCELED) { finish(); } } On Wed, Jun 2, 2010 at 12:46 PM, mike wrote: > hi NightGospel,, > > what exactly did u meant??? could you please give me a sample??? > > regards, > Randika > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en