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);
Related
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
[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>
I have a button in an Activity and when on clicking this button, some operation will be performed in another activity. And I should call the buttonclick event in 2nd activity only.Simple saying, I have a TabActivity with button and upon clicking the button some operation should be performed in the underlying tabs. ButtonClick event should be in the tab.
How can I achieve this?
create one common function in a helper class and call it from both the places.
You could broadcast an Intent from your first activity to be received by your second activity. When your button is clicked, it's parent activity broadcasts a unique intent which your android manifest will route to your second activity for receiving.
There is a good example of that here:
http://thinkandroid.wordpress.com/2010/02/02/custom-intents-and-broadcasting-with-receivers/
However, have a look at the android reference and consider using a LocalBroadcastManager which is more appropriate if you are just broadcasting within your process.
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.)
I am developing an application where one of my Activity contains a button as "Set as Home Page".
So my problem is that when I will click this button the status will be saved in the shared preference and next time when this application will be opened I want to start this Activity (the Activity which has been set as home page) instead of the default one.
So how can i do it???
You need to have defined static constant unique ID for each of your Activity. You save this ID to shared preferences, and implement on your boot activity's onCreate event a switch based on this stored ID against the static constant ID of your Activity. When you have the right step start the activity, and finish your current activity the booter.
You could create a kind of redirection Activity on which your application would start on. Then, put a switch in this activity, with intents sending to each of your activities, and the state of the preference would be the variable to test for the switch.
I'm not sure I'm clear but tell me if it's fine for you?