activity-lifecycle

IllegalStateException (Already attached) when opening NFC reader app

微笑、不失礼 提交于 2019-12-12 05:09:30
问题 I'm trying to develop an app that reads an NFC tag and displays the read data. I took most of the code from a blog but I'm getting an error when I run the application since I am trying to integrate it with the slider application. Here are my errors and my code below: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.jeffk11.tag, PID: 20123 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jeffk11.tag/com.example.jeffk11.tag.MainActivity}: java.lang

Activity Lifecycle behaves differently JellyBean onwards

浪尽此生 提交于 2019-12-12 04:59:42
问题 I have the following scenario. Activity A starts Activity B. B starts a Notification clicking on which another activity C is started. Now the behaviour is different on Gingerbread and ICS onwards. Incase of Gingerbread when I click on the Notification, the expected behavior is seen, however when I run the same code on ICS or JellyBean when I click on the Notification Activity A is destroyed(OnDestroy is called). Why is the lifecycle behavior different. How can I make it to behave in a

Save checkbox state android xamarin

梦想的初衷 提交于 2019-12-11 10:57:57
问题 I am new on xamarin and i am trying to save my checkbox state even if the app is closed because when i close it the checkbox reset to uncheck state... also.. the image that was changed resets.. is there any way to preserve both? protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.layout1); var seletor = FindViewById<CheckBox>(Resource.Id.checkBox1); var imagem = FindViewById<ImageView>(Resource.Id.imageView1); seletor

OnActivityResult getting called twice in Android

心不动则不痛 提交于 2019-12-11 09:48:56
问题 I used this code to launch an activity: Intent intent = new Intent(this, OneTimeActivity.class); intent.putExtra(Constants.HOST_KEY, host); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivityForResult(intent, 1000); And for some reason my OnActivityResult() is called twice. Once when I first call startActivityForResult and once when the result actually ends. What's also weird is that the Intent data is always null, and the resultCode is always 0 Why

Application closing on back button after viewing wireless setting by Intent.ACTION_WIRELESS_SETTING

▼魔方 西西 提交于 2019-12-11 09:28:25
问题 Similar to this question, I added no history flag to my login activity. in another side, i have a button in login activity to show wireless setting. When i press back on wireless setting intent, application closed! How can i have no history flag and prevent application from closing? 回答1: When you launch another activity your login activity is finished using the no history flag. You either have to move your wireless setting to another activity or calling finish in the login activity when

super.onCreate(savedInstanceState) crashes when activity resumes

被刻印的时光 ゝ 提交于 2019-12-11 08:13:52
问题 My app's main activity starts fine, works fine, everything is dandy - but if you switch away to another app and the app is destroyed by the garbage collector, when you move back to the app it'll crash on "super.onCreate(savedInstanceState)". This is my onCreate(): @Override protected void onCreate(Bundle savedInstanceState) { Log.d(LOG_TAG,"Activity Created"); super.onCreate(savedInstanceState); ... //Other stuff that isn't relevent } Pretty straightforward. Except when I switch away using

call method when program exits - onDestroy not reliable

丶灬走出姿态 提交于 2019-12-11 07:35:59
问题 I want to execute some functions when the program is exited by hitting the back button. This is now done by onDestroy() which works in every case but one. When coming back from another activity in some cases on exiting the program, onDestroy is not called. I know that in theory onDestroy should only be called when Android closes the app due to low memory, but for me, onDestroy works always and only in a very special case it does not. Using onPause or onStop does not work because I only want

onDetach not called for fragment?

梦想与她 提交于 2019-12-11 03:21:33
问题 I write an code to launch Activity A to Activity B. Both Activity A and B has fragment implementation. Scenario: If Activity A frequently launch Activity B which contain Fragment, then most of times it missed Fragment.onDetach..I checked with log, normally it give me following override method log: onAttach List item OnCreatView onViewCreate then press device Back Button onPause onStop onDestroyView onDetach now I press device Back button from Activity B which again launch Activity A then it

Reauthenticate on restart - Android

和自甴很熟 提交于 2019-12-11 02:19:29
问题 I need reauthenticate user credentials every time onRestart is called (usually this means the user has locked&unlocked the screen or put it on background and then returned to it). So I did that: @Override protected void onRestart() { super.onRestart(); Intent intent = new Intent(this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(LoginActivity.REAUTHENTICATE); startActivity(intent); } This works, the LoginActivity was shown, but when it finishes the

prevent task manager from recreating last displayed activity in a task

北战南征 提交于 2019-12-10 17:25:25
问题 The scenario is: launch app, start activity A, navigate to B, then to C press home button. C gets destroyed. Bring up task manager, press on my app's icon. Activity C is being recreated. How can I make this behaviour cease ? What I would like would be to go back to activity A. The closest I could get to this was by launching activities B,C with Intent.FLAG_ACTIVITY_NO_HISTORY. But the problem with this flag is that it prevents activities B,C from ever being re-created throughout the app's