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

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.)

Related

Closing the background activity which has the same name

I'm trying to develop an app which has two editText fields for entering location. So I made two java files
1.MapsActivity.java(with activity_maps.xml)
2.AutoComplete.java(with autocomplete.xml)
In MapsActivity while clicking the 'from' text field, it will open the AutoComplete activity and after clicking any of the suggestions in it will open a fresh MapsActivity and places the clicked item . Likewise for 'to' text field also.
I am using Intents to pass the clicked values. So at last, five activities are opened when the two text boxes are filled. When I click back button ,it is showing the auto complete activity used the previous time.
Question:
Is any other way to close a particular activity with same name running behind?
Is there any other way to pass values by super.backpressed(); ?
enter image description here
You can try using startActivityForResult() method. That way you can use the result from the second activity in the first and also you wouldn't need to start a new activity. You can read up on it here startActivityForResult
try to clear backstack/clear_top/single_top using the intent.
Just add/set flags in intent.
or
finish activity after startActivity.
or
you can override the onBackPressed method to call the specific activity.

Back button android implementation

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

Android: On Search Search Suggestion click every time Its opening new activity, Can we open the same activity the different data

I have implemented custom search suggestion, On suggestion click iam starting detail activity and showing data its fine, the problem is whenever i click on suggestion opening new activity for every suggestion.
eg: i have suggestions
Apple
Ball
Cat
When i click on Apple opening a detail activity with Apple data, and i have clicked on search again now Clicked on Ball and Opened detail activity with Ball data
When i click on back button it navigates back to Apple detail activity, So how can i avoid opening new Detail activity for every suggestion.
This should work for you.
Set android:noHistory=true on the detail activity in your AndroidManifest.xml.
Note : this can only solve when back button is pressed, it won't back to your Apple detail activity. It's still opening new detail activity though.
You want to control your back stack. Here is an answer that should help.
Basically, when you launch your intent you can add a couple flags that should help.
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Check the Android documentation for more info on the flags you can send in with your intent.
Good luck!

Exit child activity and return to home activity - what lifecircle is it?

[Warning: this question contains no code, so may look not interesting.]
An app has the following structure (basically 3 level of activity: home->category->item):
--- Home Activity (TabHost)
------- Tab1: category 1 activity, contains item list,
onclick item will start "viewItemActivity" to view an item
------- Tab2: category 2 (as above)
------- Tab3: category 3 (as above)
When push notification received, on click of the notification message will start viewItem Activity alone. By default, if the users hit "Return" key on their phone, this viewItem Activity will exit and user will be back to phone home screen.
Is there a way to forward user to home activity with corresponding category tab instead of going back to phone home screen?
A general method/idea would be appreciated.
I'm unsure of What part of lifecircle/method inside viewItem activity needs to be overwritten. And how to write it to avoid random affects on startup process/stack of the app.
For this overwritten method (onStop!?), I was thinking of checking whether home tab activity is running, if not then start, then pass some intent to display corresponding tab, is this the proper way to do?)
Thanks a lot!
When the notification arrives, you can start the Home Activity and in its onCreate, you can start the itemActivity. That way, in the stack, you will have HomeActivity below item activity and pressing back button will go to Home activity.
Overwrite onBackPressed() in each activity and there start your Home activity. To not have your Tab1 activity remaining on the stack, define it to have no History via the MANIFEST file:
<activity android:name=".activity...." android:noHistory="true"></activity>

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