how to do something like multiple views ..stack in iOS on Android? - android

I was wondering about the following situation:
in iOS:
I have viewA which goes to viewB on button press. from view B based on some computations, I can either go to viewC or go back to viewA.
I have done this nicely on iOS.
I am wondering how to do the same in Android. Can anyone kindly help me out ? Thanks.

You mean the Task stack on android. Take a look to this, it will be what you're looking for.
For example (I've encapsulate this in a Navigation Manager instance, that handles all my navigation logic, but given your context, something like this could be useful:
Intent intent = new Intent(this.activityC, ActivityA.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //THIS IS THE TASK MANAGEMENT
if (!params.isEmpty())
intent.putExtras(params);
this.activity.startActivity(intent);

The Task Stack in Android is correct. If you need to specifically know how to move from one activity to another then just use intents like this to change to a new activity:
Intent startActivity = new Intent(view.getContext(), TargetActivity.class);
startActivityForResult(startActivity, 0);

Related

Android dev - how to create buttons on the home screen that lead to actions

I just compiled and ran the hello world app and it worked. And I read through a bunch of stuff on the android documentation about the diff components of android and how it all works together. Now I want to make a few buttons which link to various actions.
For example, I want to make a button that goes to a new screen. Is there a tutorial for this sort of a thing? Or maybe someone could explain to me how to do that?
Thanks!
This is really simple. To make a button that goes to a new screen you should put a new button on your XML layout, and assign it an id. After you've done this, in your code, you need to do something like the following:
Button mButton = (Button) findViewById(R.id.mybutton);
mButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
CurrentActivity.this.startActivity(myIntent);
}
});
Hope this helps you.
Also, be sure that the activity that you're trying to start A) Exists, and B) is in your manifest.
The Form stuff tutorial is really useful. I believe that's the next thing you want to learn after HelloWorld.
To start a new screen call startActivity() or startActivityForResult(), depending if you intend to get data back from the new activity. You also want to learn something called Intent, which you can add information to it and pass between screens(or activity). Using intents are most often used for stating a new activity (Android dev Guide for Acticities).
Hope that's helpful.

Start Google Navigation from another Activity without setting a location

This is probably really stupid of me but how do I start google navigation WITHOUT setting a location as a lot of issues seem to come from... When I try to do this it actually starts to run Google Navigation but then just keeps restarting the Activity... Essentially I was it to run just like when you click on Navigation like you would from a home screen... So with the list of destinations etc... I presume this is a different activity maybe? I've no idea, the intent I'm using is below,
Intent i = new Intent(Intent.ACTION_VIEW);
i.setClassName("com.google.android.apps.maps", "com.google.android.maps.driveabout.app.NavigationActivity");
getContext().startActivity(i);
Finally found what Activity it is that needs starting!!!
Intent i = new Intent();
i.setClassName("com.google.android.apps.maps","com.google.android.maps.driveabout.app.DestinationActivity");
startActivity(i);

Android - start multiple activities

is it possible to start multiple activities at once? I mean, from main create 3 activities in some order and just the last will be visible? Up to now, I was able to create only one activity.
Thanks
You might need something like this in order to launch deep into the app after the user has clicked a notification in order to display some newly added content, for example.
Intent i = new Intent(this, A.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
Intent j = new Intent(this, B.class);
j.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(j);
Intent k = new Intent(this, C.class);
startActivity(k);
In this way you can start activities A, B and C at the same time and suppress transitions to activities A and B. You get a single transition from your current activity to activity C. I strongly suggest that you log the Activity lifecycle method calls (onCreate etc.) to LogCat, for example. It helps a lot in understanding the order of events.
This can be a common thing to do in response to deep linking or other use cases where you, basically, need to synthetically rebuild the Task (and all the activities it should contain). Sometimes, just specifying parents in the manifest isn't enough.
Take a look at TaskStackBuilder. One common example:
TaskStackBuilder.create( context )
.addNextIntent( intentOnBottom )
// use this method if you want "intentOnTop" to have it's parent chain of activities added to the stack. Otherwise, more "addNextIntent" calls will do.
.addNextIntentWithParentStack( intentOnTop )
.startActivities();
Really old question but I thought I still answer it.
Use:
public void startActivities (Intent[] intents, Bundle options)
Try startActivity(new Intent(...); at the end of your onCreate-Method of the first Activity.
This will immediatly launch a new Activity and pause the first one.
With back-key you will get back to the last Activity

How to navigate to another page in android?

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.

android linkify intent

I have a ListView that uses Linkify to create a link to another activity in my app. the url looks something like content://com.myapp/activitiy/view?param=blah
this works fine every time.
however, in another view, I'm trying to call some code like this:
Intent i = new Intent("content://com.myapp/activity/view?param=blah");
i.setAction(Intent.ACTION_VIEW);
startActivity(i);
but for some reason this doesn't seem to work. It doesn't trigger my activity (and in fact it blows up if i dont include the setAction() call. How am I supposed to create the Intent such that it acts the same way that Linkify does...?
Now i realize i can setup the extras and then handle it in the activity, but that just seems like duplicated effort. So instead i'll spend the time it would have taken to do that, and post this question. SO any help much appreciated. :)
ah. just figured it out:
String uri = "content://...";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);

Categories

Resources