New Activity everyday by clicking a Button - java

I want to make that when user clicks the Start Button, the app shows ActivityFirst (on the first day when he downloaded app), the second day when s/he taps Start - ActivitySecond will be shown etc. When the app will not have any other Activity, I want to show a popup that will say that more Activities will be added in the future.
I can do popups, Activities, Buttons, onClicks etc.
But I can't do that everyday will there be a new Activity.
Can you help me, guys?
My idea:
The user downloads the app,
The user runs the app for the first time and clicks the Start Button (here comes the ActivityFirst)
The user can look at this Activity for one day
The user runs the app on the second day and taps the Start Button (here comes the ActivitySecond)
And so on.
I hope you understand my idea, it's a very annoying problem to me.

What I would do, is save the timestamp of the first launch of the app.
Then, every time the user opens the activity, I would check how many days it's been since that timestamp, and populate the Activity accordingly.
All you need is one "DailyActivity", really.

Related

Android task: click a button, go to a layout to edit personal info. click the submit button, save and display the info

I am working on a small task for an android app. And I dont really know what are the things I need to do or things I should be careful for.
In a user's personal page, there is a button where the user can click in. Then it goes to a layout where there are two buttons "cancel" and "submit". Below them, there is a blank space where the user can edit his personal info. (Here the keyboard should automatically pop up).
After he clicks "submit", the info is saved and the app goes back to the personal page and the info he just entered will be displayed.
If a user already has some text for his info, after he clicks the edit button, the whitebox in the layout should has the info that he has previously entered. from that he can re-edit and submit again.
Any type of hints and guidelines will be greatly appreciated!! Thank you so much!!!
This sounds like a good place to use Activity results. You can make the screen where the user enters the information an Activity, and then start it by calling Activity.startActivityForResult(). Once the user is finished and clicks done, you store the result with Activity.setResult() and call finish() to close that activity. The original Activity that opened that screen will then get a callback in onActivityResult() with the data that you set in setResult(). This is a pretty common task so there should be plenty of examples around.

How to navigate back to my app instead of going down the backstack?

Let's say the user presses a button which causes another activity to get launched. Now the user is in another activity. What flag do I have to add to the intent, so that the user returns to my app when pressing the back button instead of navigating down the back stack of the started activity?
From the documentation, "activities on the backstack are never rearranged."
Android documentation Tasks and BackStack
You do not have to add anything to the intent. When you navigate out of you app and start another activity to complete a task, the new activity becomes kind of like an extension of your app. Pressing the back button takes you back to your app. Read This

Multiple MainActivities start on startActivityForResult() in Android

guys,
I've been working on a native Android application for some time and now I am at the end of it there is still a problem I need help with.
My project at github
There is the following problem - when user starts the application for the first time the app will ask him "When does your diet cycle starts?" with a datepicker popup. I am using SharedPreferences to store the result user has picked from the popup. I have separate DatePickerActivity from the MainActivity one that takes care of this datepicker that I start with startActivityForResult(). The DatePickerActivity passes the result to the MainActivity using an Intent.
When I debug the app I see finish() in DatePickerActivity is started twice and the MainActivity is started more than one this cause the datepicker popup to show once again.
Once the start date is set in the system there is no problem with these activities and application works fine.
Then comes the moment when user wants to reset the date - using the basket icon with text like "Изчисти" and the datepicker once again appear twice.
I hope I've been clear enough with my explanation and I am looking fowrard to hearings from you.
Best Regards,
Mihail
I managed to find a work around my problem. I guess I caused it because I need my main layout redraw after user picks a date from the picker and I doing
finish();
startActivity(getIntent());
Here should be the reason for multiple MainActivity instances in the app. Second thing I guest is that committing SharedPreferences to the OS is async and by the time I check for selected date it has not been written yet.
I solved the problem by saving picked date in static instance and when I redraw the main layout I already have the result.
Thank to those who lost some of their time trying to fix my problem!

Android application design help, How to control which activity shows

Hello I require some advice on how to approach this problem,
bear with me as I am still new to android.
I have an activity that opens on application start and requires some information from the user, but next time the user opens the app, i want the application to open a different activity that will display the various information.
Kind of like facebooks app, where when you first run it, you have to login, and only then next time you run the app you are guided straight to the feed.
Any ideas how one could do this efficiently?
UPDATE: Ive stored the information via shared preferences and am now using a controller activity that decides which step to take.
So, Controller activity runs on start up, and decides whether to show a log in screen or whether to go straight to the information. But now im encountering a problem where i end up opening a blank activity (the controller) and then another ontop of that ( the decided activtiy). I dont want the blank activity to show, so its kinda of like a background process, any ideas?
Ideally you would have a main activity like a controller. Use a SharedPreference object to keep track of whether the user is logged in or not. So back in your main activity, read this value and if it is set go to your news feed activity else show a login screen activity. (as you do the check and redirection, you can show a progress dialog)
links for SharedPreferences
MobTuts
Android Developer

Android ending activities

I go through few activities and when I want to go back to main window I use FLAG_ACTIVITY_CLEAR_TOP but if I press back button then I would go back to other activities that I went through.
Briefly speaking I want to go to main activity and after presing back button it wouldn't go to other activities.
EDITED
This clossing all activities is used to complete logoff process in another words it shouldn't user let to go back. I can't use BackPressed(), because I am using putExtra and getExtra. Maybe someone could write small sample. Because I don't understand flag system.
Use FLAG_ACTIVITY_NO_HISTORY on Activities you don't want saved on the stack. When the user presses back he/she will go to the last activity that didn't have that flag set.
You can override onBackPressed in your activity and start your desired one with the flags:
FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP

Categories