Back button android implementation - android

Is it possible to implement an Action Bar back button in android and set similar function as the back button from android device? I can not set the parent activity in manifest, because i work on a parsing News app, I have category list, when I choose one of the categories, the NewsList appears, then when I click one News from the list, and click on the back button implemented in android manifest(parent-activity), it shows error because it doesn't know which category was chosen before.

You could simply do by adding onBackPressed() in
#overrite
public onOptionSelected - method with
onOptionSelected(){switch(menuItem.getId()){case android.R.id.home:onBackPressed();break;}}

You have to start NewsActivity with startActivityForResult from Category list.
When you press backbutton from NewsActivity then send category id/name from it with setResult and handle onActivityResult in Category list screen
More details : http://www.javatpoint.com/android-startactivityforresult-example

Related

When I click back button goto previous activity from current activity android

When iam moving current activity to list activity in list activity have 8 items and in list activity have add button widget when I added one item using add button so total 9 items in list activity. Here my problem is when I click on back button my application not moving to previous activity showing list activity with 8 items after click again back button moving previous activity how to solve this issue without using intent
override onBackPressed() method the way you want.
When you use realtime database like Firebase at the moment you will have updated list. I think when you click on button you are opening new activity and don't finish last one. So you come back to last view again. Of course if you send your code, you will get proper answer.
You should override method onBackPressed() in the activity where your back button is not working correctly for you:
#Override
public void onBackPressed()
{
finish();
super.onBackPressed();
}
I think that adding method call finish() should solve your problem.

Android app - delete item from list following an action in another activity

I'm creating an app where I display a list of pending challenges. When the user clicks on a challenge, he can accept it or ignore it.
Here's what I want to do and I don't know how :
if the user accepts or ignore the challenge, call this.finished and remove the challenge from the list
if the back button is pressed, do nothing, the challenge is still visible
In short, if the user really responds to the challenge I don't want it to be displayed in the list, but if he doesn't choose any option and press the back button, he didn't choses one of the two actions so I want that challenge to still be visible in the list.
I don't think it's possible to detect what button I've pressed when i go back to my main activity. I've thought about using global variables, but I don't want to misuse them either.
Just to be clear, I'm not asking how deleting a list item. But when to know deleting one depending of the actions of another activity.
Give your second activity the index you want to remove as a parameter inside the intent and let it finish by returning the index again as an intent extra (by using setresult(Intent i) and then calling finish) inside your first activity catch the result from your second activity by overwriting onActivityResult (http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent))
see 3.3. Retrieving result data from a sub-activity in http://www.vogella.com/tutorials/AndroidIntent/article.html for a detailed howTo

When i Click Back Button in android i want to make changes in previous activity?

When I click back button in my app I want to change some data in previous activity.
public void onBackPressed() {
super.onBackPressed();
Log.v("Back Button ","Pressed");
}
I am trying to using this but cant help it out ?
do I need to maintain backstack of activities which back button internally does?pls help
i want to change menubar images (wriiten by me bottom of every activty in my app) item which is present in every activty but when I click menubar (clickable) it is not able to change menubar images as per activity changes.
You want to look at startActivityForResult. The previous parent Activity should spawn the next one with this call. Data can be passed backwards via extras (Bundle) in an Intent when returning to the parent Activity in onActivityResult - or you can simply use the result codes.
You can find more information here: http://developer.android.com/reference/android/app/Activity.html#StartingActivities
Better use with onKeyDown. & onKeyDown Example
Just override this android's default method. It'll provide the changes with whatever you want.

Open the first activity on the current tab by clicking same tab

Is it possible to open any acticity on the current tab by clicking the current tab itself?
What is to be done in my application:
user performs a search , a listactivity is displayed on same tab(Using TabGroup activity). Then If User presses the same tab, again the search page should open.
Is this possible?
Try this,,,,
Rather than starting two activities, you perform both in same activity.
On pressing tab show search activity.
show search screen, when user clicks search, get your search result and set it as current activity view i.e, setContentView(list);
when user clicks search again start SearchActivity again (as usual).
Refer this link:
Launching activities within a tab in Android
In first answer,you can set SharedPreference Variable and then check for that variable to know which activity to be loaded in this tab(in YourActivityGROUP class).you can set Extras to Intent accordingly in your main activity which you use to open an activity in a tab. (I haven't tried this,but i think,this will solve your problem.)

Android: get activity from tab or intent?

my app uses a tab bar, each tab button associates an Activity, so when you click on a tab button, it shows the screen for that activity, now it need to detect user click on current/active tab button, I've already finished the code to detect that, but now I need to inform the corresponding activity of the click, is there any way to get the activity associated with tab button? Or can I get the activity started by an intent, if I have the reference to the intent?
Thanks!
It's a little late for your answer but you can try :
String tabTag = getTabHost().getCurrentTabTag();
Activity activity = getLocalActivityManager().getActivity(tabTag);

Categories

Resources