I have an activity where on the last fragment there is a button to send the user to ACTION_INPUT_METHOD_SETTINGS. Then when the user presses the back button, it's still my last fragment. I make the INPUT_METHOD_SERVICE appear, but when something is selected on that dialog, I want to reload my activity. I know how to reload the activity but I don't know how I can detect when something is selected on the INPUT_METHOD_SERVICE.
This is the way I read my activity in onResume:
Globals.securityWizardPage = 4;
Intent myIntent = new Intent(v.getContext(), SecurityWizardActivity.class);
startActivity(myIntent);
getActivity().finish();
Related
I'm trying to go back to main page fragment when user click to 'Done' button. It can be like swifts' "dismiss()" function. However, I dont know what am I using like that function in android.
My code run like; open activity from fragment and this fragment load detail fragment.
First of all, the first fragments' adapter open the second fragments' activity :
Intent intent = new Intent(view.getContext(), DetailActivity.class);
intent.putExtra(Consts.EXTRA_OFFER_DETAIL, binding.getController());
view.getContext().startActivity(intent);
After that, activity open fragment automatically
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container_fragment, new DetailFragment(), null);
transaction.commit();
And I want to close last fragment when user click alert dialogs' done button
builder.setNegativeButton("Done", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
getActivity().getFragmentManager().popBackStack(); //That is what I tried but doesnt work
}
});
I'm not quite sure about your activity and fragment workflow but to close the whole activity you can just call
finish();
to dismiss the whole activity.
Since there is no fragement in the backstack, popBackStack() won't do anything.
If you only wnat to dismiss the fragement, you should use:
super.onBackPressed();
I have an activity A which uses a fragment A which has a list. The activity A can call on a search activity. The problem that I am seeing is if I were to go the search activity and then go back to the activity A, from there fragment A gets loaded. If I select an item from Fragment A i get taken to Fragment B, if i were to press the back button i have to click it 2 or 3 times. Any ideas? Do i need to start the search activity with a parameter so it does not add to the back stack. I have tried the Flag to Intent.FLAG_ACTIVITY_CLEAR_TOP when starting the search activity but the issue occurs.
Java:
Activity A:
public void popFragment(){
if(getSupportFragmentManager().getBackStackEntryCount() > 1) {
getSupportFragmentManager().popBackStack();
getSupportFragmentManager().executePendingTransactions();
}
}
Fragment A:
private void showSearchActivity(){
Intent intent = new Intent(context, SearchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, 0)
}
i want to create an app with navigation, wiyh navigation flow like this
ListView Activity -> Detail Activity (item 1) -> Detail Activity (item 2)-> Detail Activity (item 3) -> ... and so on
is this posible? how to achive this?
Edited
Sorry for being not clear,
Lets say i have activity with ListView, then when i tap one item, it will start new activity which contain detail information of selected item, and from those activity, there are next / previous button, and when i tap it, it will start new activity using same class and layout, but with information of next or previous item of ListView previously selected item.
Oh and also I need that user can return to previous screen on each backkey, so when user tap back key the activity will go like this
Detail Activity (item 3) (finish) -> Detail Activity (item 2) (finish) -> Detail Activity (item 1) (finish) -> ListView Activity
Do this way
Yes this is possible to call Activity call it self, because Every activity is different process in android.
Activity stack will maintain by Android Don't worry about that.
public class ListActivity extends Activity {
// call DetailAcitvity
Intent intent = new Intent(this, DetailActivity.class);
intent.putExtra("item", "item1");
startActivity(intent);
}
public class DetailActivity extends Activity {
// Calling itself
Intent intent = new Intent(this, DetailActivity.class);
intent.putExtra("item", "item2");
startActivity(intent);
}
I am making a contact list application, and i have a main screen that helps you save a contact. I have a search button there. Then i created another UI that i call it search screen. When i click on the search button on main screen, i want to be redirected to the other UI, i.e. search screen. I am planning to add setOnClickListener method for search button but how can i switch from main screen to search screen when i click the button?
btn_goSearch.setOnClickListener(new OnClickListener() {
?????????
}
});
Thanks
#Override
public void onClick(View v) {
Intent intent = new Intent(Currentactivity, YourSearcgActivity.class);
intent.putExtra("EXIT", false);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
you should create another Activity, maybe call it SearchActivity, and when the user clicks the button, just start SearchActivity with a simple intent, that will load its own layout and everything:
startActivity(new Intent(context,SearchActivty.class));
I have two activities in my application. Activity1 has a list view and two buttons(say button1 and button2). Based on which button user clicks the content in the listview changes accordingly. The default loading of activity is having button1 click contents loaded in activity1.
In my Activity2, I have a button(say button3) which when clicked, has to load activity1 but with the listview loaded with button2 click results, not with the default display which shows the button1 click results.
Any help on how can I acheive this? On the onclick event of button3 in activity2 I can load activity1 but that will load with the default state showing button1 click results.
Save the state of your ListView by passing a extra string with IntentHandler when switching between the activities:
Intent intent = new Intent(getBaseContext(), yourActivity.class);
intent.putExtra("LISTVIEW_STATE", myListViewState);
startActivity(intent);
Then in your recieving activities onCreate() method (in this case yourActivity) you can get the state with:
Intent intent = getIntent();
String recievedListViewState = intent.getStringExtra("LISTVIEW_STATE");
From second activity send Intent with a flag.
In first activity always lookout for this flag and trigger your second button code accordingly. For reference you can search for "passing data between activity" here or google.
You can do this by adding Extras on your Intents. Right now, when you start Activity1 from Activity2, you probably have code that looks something like this:
Intent intent = new Intent(Activity2.this, Activity1.class);
startActivity(intent);
You can use the putExtra() method on the Intent that sets a key-value pair (called an extra) on this intent, making it look like this.
Intent intent = new Intent(Activity2.this, Activity1.class);
intent.putExtra("LIST_TO_DISPLAY", "LIST_2");
startActivity(intent);
The first argument to putExtra() (the key) is always a String, the second argument (the value) can be many different data types. Here's it's also a String.
Once Activity1 starts, you can grab the Intent by using getIntent() then pull the extra from it, all in onCreate().
protected void onCreate(Bundle b)
{
Intent intent = getIntent();
String whichList = intent.getStringExtra("LIST_TO_DISPLAY"); //which List now equals "LIST_2"
if( whichList != null && "LIST_2".equals(whichList) )
{
//Set up List 2
}
else
{
//Set up the default list
}
}
Here's the docs for the Intent Class. You can find explinations of all of the put and get Extra methods, as well as some other information that may be helpful when wanting to customize how you started Activities behave.
I dont understand so there are several things which would you think.
...
Activity1 -> Button1 -> Listview (Content A)
Activity1 -> Button2 -> ListView (Content B)
Activity1 -> Activity2 -> Button3 -> Activity1 -> ListView (Content B)
So you could
in activity1
start startActivity(intentActivity2);
In activity2
intentResult.putExtra("cmd", "button3");
onbutton click setResult(RESULT_OK,intentresult)
and finish
back in Activity1
onActivityResult
resultIntent.getExtra("cmd")