I'm pretty new to Android applications. What I have at the moment is an "app", which displays a login screen, and users can log in. What I want is, if the login is correct, to "forward" or open a new window, where users can change some settings etc... So really, I only need help with creating a new window.
How would one do that? Make a new activity perhaps?
Thanks
That's right, you just start a new activity with startActivity()
Intent intent = new Intent();
intent.setClass(this,SecondActivity.class);
startActivity(intent);
This means the class you come from, so the current one. SecondActivity is the activity you want to start.
Related
I am thinking, how to set up the new window in Android after pressed button. I have the first window, when I have a few buttons. After pressed one of these buttons (for example on the button for adding new name) I want to show new window, when will be only Edit text for new name...
Any ideas, how is possible to do or where to search inspiration?
Thanks a lot,
Manny
You need to start new activity.
Intent i = new Intent(ActualActivity.this,ActivityB.class);
String name = "example"
i.putExtra("NAME", name);
startActivityForResult(i, ID);//or startActivity,see javadoc for your preferences
With "startActivity" or "startActivityForResult" you call the new activity. For that you need to create a "Intent". If you want to send information like a name, or a number or something else you can "putExtra" information like the example.
(Ofc ActivityB must to extend Activity and must be declare in AndroirManifest)
EDIT:
You have a lot of example of how to start new activity in the SDK examples (sdk directory/samples/android X )
I'm new to android. Please tell me how to navigate to a new page in android.
Thanks in advance.
Edit:How to start a new activity from an existing activity
In android to navigate to another page means you have to start another activity. for starting a new activity use this
Intent intent = new Intent(currentActivity.this, nextActivity.class);
startActivity(intent);
You should mention the next activity in the AndroidManifest file.
To change your page (i think you're refering to "Activities" in android you need to issue a so called "intent").
You cann do that by:
startActivity(new Intent(nextactivity,NextActivity.class));
or
startActivityForResult(new Intent(nextactivity,NextActivity.class),1);
if you want the new Activity to return any result to the activity who started the new one.
But what i recommend is, that you read this documentation here:
http://developer.android.com/guide/topics/intents/intents-filters.html
and come back to this question if you have need additional assistance on concrete problems on that topics.
i hope that helps.
I am still not completely sure of this opening a new screen with a new intent. I have two problems. 1 is getting it to work and the second is more theory.
Firstly I have two packages com.quiz.max and com.reason.max both have activities names accordingly eg Quiz and Reason respectively. Here is the on click code I am trying to execute at the moment in quiz to go to reason.
Intent intent = new Intent();
intent.setClassName("com.reason.max", "com.reason.max.Reason");
this.startActivityForResult(intent, requestCode);
Secondly I heard if I start this intent then everytime i click the button a new intent is created. Does this mean if the user goes to reason page and navigates back and clicks the button again they actually create a new intent instead of going back to the already active one. Thus dozens could be opened via this method. Therefore should I close each reason intent once navigated back or is this a redundant point?
Max
I think you want
Intent intent = new Intent(this, Reason.class);
startActivityForResult(intent, requestCode);
Secondly, you don't "start an intent". You use an intent to ask an Activity to start, in this case the Reason activity. And yes, the default behavior is to start a new instance of the activity each time it is requested.
You can alter this behavior with the launchMode.
Make sure you read and understand the Activity lifecycle. You don't need to worry about too many Activities in existence, Android will handle that for you, but you should properly save state and clean up connections in the appropriate lifecycle methods.
Im having trouble getting this to work, hereĀ“s a quick overview of the idea.
First, I cant change the logic behind this, it was a specific requirement from the customer, I realize that with any tool such as AnyCut it could be bypassed but that doesnt matter really.
My customer offers a suite of apps, the idea is that all applications bellonging to the suite would be launched from a "Dashboard app", so that I only show the Dashboard app in the main launcher and not all app icons.
Lets take two Apps to get the idea solved. The Dashboard App (A) and the Recieving App (B).
I want to establish an intent filter (I think) on app B so that whenever I go into app A, and click the app B icon the app will be either launched or started from where it let of (brought to front).
Is this even possible? If so, how can I do it? I managed to get it to launch by specifically launching one activity in the app using:
Intent i = new Intent();
i.setClassName("PACKAGE_NAME","SPECIFIC_CLASS");
startActivity(i);
But that isnt the behaviour that I want, as it always starts app B in the same spot.
Thanx in advance,
Stefano
Edit: Added some new information. I was taking a look at the DDMS.
If I launch the application from scratch through the main Android launcher the intent is exactly the same as when I leave the home button pressed and then only bring the app to front, what ever activity im in. So I was trying to reproduce, unsucsesfully until now, this intent.
INFO/ActivityManager(1292): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.package/.uiPackage.Activity}
This is how AnyCut does it
Intent { act=android.intent.action.VIEW flg=0x10000000 cmp=com.example.package/.uiPackage.Activity bnds=[125,242][235,360]}
Any idea how I could go about creating that exact same intent? I cant even find that flag in the Intent API.
Figured it out, this is how I did it.
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setAction("android.intent.action.VIEW");
i.setComponent(ComponentName.unflattenFromString("com.example.package/com.example.package.activityName"));
startActivity(i);
I'm not quite sure I'm following the expected results you want to see, but the following would launch the app from the dashboard and remove the dashboard from the activity stack leaving the selected app running:
Intent i = new Intent();
i.setClassName("PACKAGE_NAME","SPECIFIC_CLASS");
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
I believe this should start the app as if you were starting any other app.
Please add more information on your logic if this is not what you are looking for.
I think that when you switch activities android's default action is to sort of pause or hold the activity in its state the user left it in last. I know there is a way to make it so that the state is not saved when switching activities but I cant remember it off the top of my head.
I know it's kinda hard to understand the question, I'm new to Android, what I mean is that:
say I have an activity A that is currently active, then I put device sleep and wake up the device, activity A still active right now.
At this time a dialog will pop up and I press "Yes", a new activity A will be created. What I concerned is that, how do I kill the old A and then create the new A?
Right now when I click "Yes" the new A is created but it's not showing correctly.
I'm not sure what are trying to achieve, but this code snippet should do what you want.
finish();
Intent intent = new Intent(this, YourActivity.class);
startActivity(intent);
A different alternative is calling
recreate();
As the documentation says: This results in essentially the same flow as when the Activity is created due to a configuration change -- the current instance will go through its lifecycle to onDestroy() and a new instance then created after it."
Try this, hope this will help.
Intent intent = new Intent(this, yourclass.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();