So I have an App that switches between activities using the onClick() method. One click takes you from the main activity to activity 1-6. Upon clicking activity 1-6, it will take you back to the main activity. I need a method that will upon clicking the main activity 3 times, will take the user to another, custom, activity.
It's a simple process, but I haven't seen any questions like this here on stack overflow.
Related
me and a partner are working on a project and have designed an app that uses nfc, we want it so that when you're off the app you can tap an nfc card and read it as well, the problem is we don't specifically have an activity for reading or writing a card, its triggered using a button on main activity that starts a dialog fragment, starts a class and reads the card
is it possible, using the intent filter (or any other way without having to create an activity for it) trigger a method in the activity? at the moment we just have it to bring you to the main activity but we want to start a method in main activity when that happens.
Intent filters start Activities. Activities always start with onCreate. If you want to call a single function in your activity, your code is mis-architected and that function should be in a common helper class, not in your activity.
I have a multi-fragment form dividing sections of a form. When the user is finished they hit the submit button at the bottom of the screen which is owned by the hosting activity. When the user clicks submit all the fragments should send their data to the activity and then the activity handles the networking. So I have onClick listeners set for the same button in every fragment, as well as the activity. However when I hit submit onClick only runs once, in some fragment (never in the activity), when it should run 5 times (because I have 4 fragments and 1 activity). Basically I need the fragments to deal with the click and then the activity deal with the same click.
Use the Observer design pattern where the activity is the Subject and the fragments are the Observers
I have a question that I've been looking for answer to for several days with no luck.
So, to be as specific, I have TabActivity inside TabActivity and listview inside it (I call this entire screen "main screen"). That listview is populated from data sent from my database. Upon clicking an item of the listview, I start an activity but upon exiting that activity and coming back to the main screen, the listview is recreated and I was wondering whether there was a way to stop from being recreated.
Which method do I need to override to simply start and finish activity without destroying the main screen?
Edit--
I don't have FLAG_ACTIVITY_CLEAR_TOP attached to any of the activity
I have an applicaton, which need a pop up to be shown from a service for which I have started an activity with flag Intent.FLAG_ACTIVITY_NEW_TASK. It has two buttons A and B. After clik of both buttons I am finishing the activity.
But even after I finish this activity (pop up), when I select my activity from recent activities (If i long press home button), I am directed to the pop up activity. How do I go my application's main stack?
I have an app that circles around the main activity (a main menu). In each other app there is an option menu item that directs to this activity.
At first, I always started a new main activity when this item was selected. Using the intent bundle, I did tell the main activity that some initializations I do on a fresh start were not necessary.
However, I didn't quite like the overall behavior. I stumbled upon android:launchMode="SingleTask" and this seemed to help: now I don't recreate my main menu activity all the time; also, if I press the "back" button I come back straight to the home screen. This feels quite nicely like a proper "main" menu.
My problem now is this: if I run another activity of my app, press home button and then reopen my app (e.g. using "last apps"), then I don't go back to the last activity, but to the main one. The other activity is destroyed.
Any ideas how I can implement the behavior of SingleTask without only being able to return to one activity?
If your other activities are declared normally with activity defaults in Android, then going back to your app should take you to the same activity where you left off (using the hardware home button)
However remember that the Android system kills applications when it requires system resources. So your app may have been killed when you went to the other application. Then when you get back to your app, the default launcher activity will be restarted, which is your Menu activity.
To get back to the main activity from any activity, do this:
public static void goHome(Context context) {
final Intent intent = new Intent(context, HomeActivity.class); //give name of your main activity class here
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
That will clear the activity stack and get you back to your main activity. As you declared singleTop, it will bring the existing main activity to the foreground. The flag Intent.FLAG_ACTIVITY_CLEAR_TOP will remove all activities in the stack on top of the main activity. (I am assuming you are within the same application).
Now, all your other activities only need to include a button whose click listener invokes the method goHome();
From your main activity, if you press the hardware back button, it should exit your app.
Why not call finish() on the activities that were created by the main activity? This way you return to the main activity, without creating a new one...
I think you should save the state of you activity before starting another activity, and then resume your activity whenever you come back on last activity.
see Activity Life cycle from Android
http://developer.android.com/guide/topics/fundamentals/activities.html