How to open an Activity from Slideout in Android? - android

I downloaded from Android.com an example of Navigation Drawer (I want to make a Slideout)
but, in that example when I click in a item of the slideout, this will open an image, so, How can i open an Activity instead of an image?
please help me.

Use this code on press ( Button press or whatever is relavant to you)
Intent intent = new Intent(Currentactivity.this,Activitytoopen.class);
startActivity(intent);
Here:
1) Currentactivity.this should be replaced with the class name you are currently on.
2) Activitytoopen.class should be replaced with the activity name you want to navigate to.

Try to use this codes
Intent i = new Intent(Activity.this,NextActivity.class);
startActivity(i);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);

Related

Android - start Activity and back Issue

I have one issue that currently face.
For example as below:
Activity A
to
Activity B
to
Activity B
then in third page, i click back, is go to first page, not go to second page.
i use like below code for go next page in Activity B.
Intent intent = new Intent(act, Activity_B.class);
intent.putExtra("Sample ID", "1");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
i use below code to back in Activity B.
super.onBackPressed();
So does anyone face this problem for back button issue ?
please advice.
thank you.
Remove from your code this line:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Look here for more information
If you are targetting Android 4.1 (API level 16) or higher you can set the up navigation in the manifest.
And in the activity, when you go back it will go to the parent.
Android developer dox:
Providing Up Navigation

Using life cycles in android

I'm a new android programming beginner :) .
I have made a simple app which adding places .
1- Main activity include buttons{Places , Add place , Favorites Places }
so let's assume we are in the "Add place" activity , we type tite and description and add the place to arrayList, and move on to Places which has this list ..
The problem is when I type back, I get back the details I wrote about the place, but I'm trying to clear it when I press back in the phone ...
how can I do this to avoid crashes ?
Thanks all
-- Update :
Thanks to all people who reply trying to help me, that's awesome :)
I just added :
#Override
public void onBackPressed(){
Intent intent = new Intent(PlacesActivity.this,MainActivity.class);
startActivity(intent);
}
This solution was suggested by : Arsen Sench :)
in the activity that I don't want to press back,
You can do one thing here.
Before jumping to another activity View Places , just clear all the edittext there.
edittext.setText("");
Try this. Will help you.
just clear the EditText field before you start a new activity
editTextTitle.setText("");
editTextDescription.setText("");
intent.startActivity();
You can use startActivity() from both classes. Or you can use startActivityForResult(). Here is example of using startActivity() from both activites.
From first Activity
Intent i = new Intent(YOURFIRSTACTIVITY.this,YOURSECONDACTIVITY.class);
startactivity(i);
finish();
From Second Activity
#Override
public void onBackPressed()
{
Intent i = new Intent(YOURSECONDACTIVITY.this,YOURFIRSTACTIVITY.class);
startactivity(i);
finish();
}

Activity is not calling back from browser

I have an activity that takes an "intent" to the browser, I see the page on which connect and when I return to my work I press the button to go back to my activity. The problem is that it gets stuck in the browser. Is there any solution? Thank you very much for everything and sorry for my English.
here is my code
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(/*my url*/));
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);
The Intent you used is just to open browser. If you want to handle the result then you need to consider implementing Custom WebView Activity. So that you can do what ever you like with the browser.
Ahhhh... My bad.!!!!.. I have checked my manifest file ..and I have put NoHistory=true on my parent actvity.

How to create a shortcut button to jump to a DialogPreference

I would like to make a button on the front page of the app that jumps to a specific DialogPreference.
The purpose of the button is to be a shortcut to that preference, bypassing having to browse the list of all preferences, since I'm going to be resetting that preference a lot.
If it's not possible to make this button, can someone give me the source for DialogPreference (I don't have enough space to download the source tree).
You can use android.provider.Settings.* intent to do this... for example, if you want to open the GPS settings page from your app, use the following code:
Intent myIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity(myIntent);

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.

Categories

Resources