My app use fragment to serve as pages.
I need to different things when i "go to" the page vs "back to" the page. But this both triggers onCreate life cycle for the fragment. How do I distinguish them?
Related
how can facebook hide current activity and show another activity here in chathead
when choose another one to talk with him its hide current popup floating activity and show the other one activity
i don't think its start new activity because i write some message on current activity in the editText without send it and when choose another one to talk with him its hide current activity and when i back open it the text i write it it's still there thats mean it's dosen't start new activity when switch to other conversation
iam try to make something like facebook chathead but i have problem i switch between floating activities
They are using Fragments and Floating Action Buttons.
Also just for your information, unless you specifically call finish() on an activity, it will only get stopped when the new activity is started. When you return, it will go back to onResume() state.
Please look into activity life cycle and Fragment Life cycle to know about these things more clearly. The faster you have a clear idea about these, the easier it will be in the long run
https://developer.android.com/training/basics/activity-lifecycle/index.html
https://developer.android.com/guide/components/fragments.html
NOTE: When it is on the home screen, It is an window running on top of the background service with a floating window , while inside the app it is a Fragment.
see tutorial: http://androidsrc.net/facebook-chat-like-floating-chat-heads/
I experience a very strange problem.
From the MainActivity of my app, by clicking on one of my menu button, a new screen / fragment called MyFragment is loaded.
On the MyFragment screen there is a button called MyButton. If the MyButton button is clicked, it opens a link on a browser.
The problem is that, from the browser, if I click on the Back device button, the behavior is very different depending on the device I test the app (and you will all agree it should NOT) :
on a Samsung Galaxy Tab 2 tablet, the app gets back to its previous state, with the MyFragment loaded and opened (just as if nothing changed from the moment when I clicked on MyButton).
on a Nexus 4 phone, the app is like reset (and then the MyFragment is not loaded). Basically the previous state is lost.
Any idea ?
Here is the piece of code I call from the MyButton click event.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.example.com"));
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // I tried this but no luck
startActivity(i);
Thanks in advance.
It sounds like on some phones your Activity is geting killed by the OS. Android has the right to kill any Activity that goes in the background if it needs to reclaim the resources that it's using. This is the expected behavior. To mitigate this, you'll need to manage the Activity Lifecycle. The important thing to note from that page are that onSaveInstanceState() will allow you to save your state if the OS is about to kill your Activity, which will restart the lifecycle with onCreate() and provide you with a Bundle that contains all your saved state information.
Additionally, fragments have their own lifecycle, with the equivalent onSaveInstanceState() method, so any Fragment-specific info should be managed there.
Answer : on the Nexus 4 "Developer options", the "Don't keep activities" option was set to true. That's why...
I have 2 activities, 1 for registeration and 1 for the main page of my application.
Now in order to choose between them I have to create another activity that checks some details and decides to which activite to go.
The problem is that after I choose the main page activity I have 2 activities on the background and when I quit my app I have another empty page.
The page thats check those things don't need a graphical layout.. how can I solve this case?
btw if you have a better suggestion for my title let me know.
Thanks.
In our application we tackle similar problem differently. Our approach would work like that for your case:
Always try to launch Main Page.
At the startup of Main Page check "some details" and if you decide that Registration needs to be launched - do that.
When you want to go from Registration to Main Page, just finish RegistrationActivity and you'll go back to Main Page.
This way back button on the Main Page won't take you to the Registration and you won't see any "empty page".
I'm quite new to android and have a questen concerning an personal menu.
I want to make several activities use one menu. So i created a header.xml file, which I include in all the activities. There are 4 images in the header, I want to make them clickable (which is no problem with the android:onClick function), and I want to show the user which activity is running.
So i want to replace the "activity 1" image with an "activity 1 active" image and so on. When clicking on "activity 3", the menu should use following images for example:
activity 1, activity 2, activity 3 ACTIVE, activity 4
Furthermore, the active images should not be clickabel, because this would refresh the page.
I would be happy about ideas how to solve it! (project should run with android:minSdkVersion="8")
greets
For showing the user that he is in which activity you can show a Long or short Toast message in OnCreate like
Toast.makeText(getApplicationContext(), "Welcome in activity 3",
Toast.LENGTH_LONG).show();
And for Stop clicking function you can cancel the OnClick() of your button by using:
image3.setClickable(false);
Today I was testing my app (wich is a very simple note application) but some strange behaviour occur .
The app consists of a big ListView which displays all the notes and a button to make a new note (activity A).
When I press the button to "Add new note",it takes me to the activity B
(with all the fields like title and text).
When I press "Add" ,it take me back to the activity A and displays ok
the new Note .
The thing is that I started pressing BACK and it began to take me "back in time" where some notes were still not created,until it reached the time they were 0 notes .
Since I am new to Android devel ,is this normal or is it something wrong with my app ?
When you go from one activity to another then you should finish your activity and then start new activity.
Try the below code:
finish();
startActivity(new Intent(CurrentActivity.this,NewActivity.class));
You probably need to implement some sort of refresh method to update your ListView. Depending on how you are persisting the data, you could create a method that retrieves the latest data and then updates the adapter for the ListView. Once you have that implemented, you should call the method in onResume().