Homepage activity - android - android

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".

Related

How can i switch main activity not in manifest?

I making android app. I have 3 activites:
first(main) activity which is empty and it's like navigation which ask you to add item.
Second activity which is needed for adding item's details and this activity have accept button which leads you to third activity.
Third activity have all data about item and from now on i want my app to make this activity main (default) activity with saving information about it in device memory.
I decided to make it without database because it should be really simple.
Can you help me with making 3rd acitivity main? Maybe there are some tricks.
not clear what you trying to ask. Like if user reached the 3rd activity, in the future if user open the app the app will automatically navigate them to the 3rd activity?
If that's the case, you could save this information in the shared preference, when the app start, the first activity check this value and navigate to the 3rd activity.
Recommend you use a single activity, use fragments for different pages, and use Navigation component to connect them. https://developer.android.com/guide/navigation/navigation-getting-started

App appears in task switcher more than once

I am developing my first app now and I see that whenever I click on a new activity it opens up and everything is fine. I can also go back to the main activity and then open a different and it all works.
However once I open the task switcher, all the previous activities show up. They all show up as seperate apps and if I click on one of them that is not the main activity I cannot go back the to the main activity its like its very own up with just that activity.
This is very strange. Does this have to do with how I implement the onDestory method? Because to be quite frank I never used it.
Please help me!
Thank you!

How to finish a specific activity in android

I know you might think that this question have been asked a lot, but I've been looking into different cases, all cases they just want to close all activities when logged out. Here is my scenario:
1) Start the app with Splash Screen then I used finish()
//I set this activity as MAIN so it's first to open - that is why I cannot setFlags(FLAG_ACTIVITY_CLEAR_TOP) because it basically goes back to MAIN
2) Introduction Pager(4 sliding pages) with Login and Signup buttons
3) Login and signup buttons direct you to corresponding activities
// I didn't use finish in introduction pages because I want the user to have the ability to go back to introduction if for example pressed signup by mistake
4) after performing login/signup the user will be directed to the homepage(Here I used finish to kill login/signup activities because I won't need them anymore)
So all previous activities are now finished except for the introduction pager, when the user press back the app will finish homepage and go back to introduction, but I don't want that! I just want the app to quit, I don't want the introduction pager to be running on the background. How do I finish introduction pager when onCreate method is called in homepage?
I have another related question I didn't want to post another thread for it: how to get the previous activity? like I don't want to use the action bar to navigate, I created a button (<- Back) and when I press it I want to bring the previous activity, how do I get the previous activity?
First of all make your IntroductionActivity a single istance in the manifest like this: launchMode = "singleInstance"
There are many ways you can do this, the fastest, I guess, is to use a static field that refers to that activity. Add this in your IntroductionActivity:
public static Activity mActivity;
onCreate(){
this.mActivity = this;
}
Then when you reach the homepage you can do this:
onCreate(){
IntroductionActivity.mActivity.finish();
}
Use finish(); after you start the next activity
Example:
Intent itr=new Intent("com.example.splash.Second");
startActivity(itr);
finish();

Android Multi-Screen Application

How do you handle multiple screens in an android application? I have developed with the tab bar at the bottom without problem, however what I am wanting to do is replace all the content on the screen with the content from a new .xml layout file I have created in the project. Additionally, how would I tie the back end code to the new layout file? I'm sure this question probably exists already and is googleable (may have made up a new word). However, I don't know exactly what it is that I am looking for. Thanks in advance for your help.
What you need to do is, create a new Activity and add it to the AndroidManifest.xml:
<activity android:name="ActivityClassName" android:label="Label for the Activity"></activity>
and can be called in a method:
public void startActivity() {
Intent someName = new Intent(CurrentClass.this, ActivityClassName.class);
startActivity(someName);
}
Android applications generally use a separate Activity for each screen, and switch between them using Activity.startActivity and Activity.startActivityForResult. You can pass arbitrary data to an Activity via Intent.putExtra.
Hope this helps,
Phil Lello
It really depends on how you want your application to flow.
Let's consider the scenario where a user does the following:
Starts your first activity
Presses the 2nd tab
Presses the 3rd tab
Presses the back button
If you use a separate activity for each screen, then the following would happen
Activity 1 is started
Activity 2 is started
Activity 3 is started
Activity 3 is closed, user returns to Activity 2
(in this case pressing the back button again would you take you back to Activity 1, and pressing it again would exit your application)
If you used one activity for all the tabs, then the following would occur
Activity 1 is started
Activity 1 sets tab content to tab 2 content
Activity 1 sets tab content to tab 3 content
Activity 1 is closed, user returns to home screen
If you are using a screen with tabs, then the second method (a single Activity with a TabHost or similar) is the preferred method, otherwise the user will end up making a large activity-stack just switching between tabs (meaning if they switch between tabs a lot they'll have to press the back button a lot of times to exit).
If you want to go for the single activity approach, then do some research on TabHost and TabContentFactory. In the createTabContent method of your factory you can inflate a View/layout from XML to set as the tab content using View.inflate. Look those up and come back ask another question if you get stuck ;)
i think you may want to play with more than one activity.... you can have multiple activities and one xml for each of them... in this way you can have different screens... check these links. Multiple Activities, Creating an Activity.... hope this helps...

How would one design a flow where one of the screens is a login screen?

I am writing an Android app which requires the user to be logged in. I have a main Activity, and I want that when the app launches, that it takes the user to a login screen if they are not already logged in.
How should I model this? Is the login page another Activity? I'm thinking not because I don't want the user to be able to get back there using the back button. Or is there a way to replace an activity with another so the back button problem doesn't happen?
Or, should I have just one activity and load in a login view and swap it out once the user logs in?
Are there any best practices around this?
Thanks!
I would check on the main or splash screen to check if the user is logged in, if not start the login activity.
Once the login completes, in the login activity, call this.finish()
If you need to change activities, you can call .finish() followed by starting whatever activity you wanted.
If getting back to the splash/main screen without being logged in is a problem, you can do the same thing there.
For this ask "I'm thinking not because I don't want the user to be able to get back there using the back button"
The answer is using the attribute noHistory in your Login Activity, like the example:
<activity
android:name="com.test.LoginActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:noHistory="true"...
I hope it can help.
Yes, the login screen is an another activity. The back key problem is solved with onKeyDown() method of that activity. Read more here.
The whole flow can be imagined like this:
You're starting your app. The main activities check for login flag(in shared preferences or somewhere else). If user has logged in, then the main activity stays on the screen. If not, activity starts login activity using intent. Login activity performs the logging in and sets the login flag and start the main activity again.
Have you considered using a dialog for the login? I suppose what you could do is have the first Activity check at onCreate() using SharedPreferences if the user has already logged in, and if she hasn't then it generates the dialog. After logging in the dialog would change a variable which would be passed to SharedPreferences so that the user won't have to relogin if the screen orientation changes or the app pauses.

Categories

Resources