Hi, quick question hopefully.
I have a main activity. It looks up units (ml or oz) onCreate and changes a few TextEdits.
If I then launch the settings activity, change the units and then return to the main activity the wrong unit is displayed.
Question, how do I run code every time an activity displays?
Cheers
Sent from my HTC Desire using XDA App
Put your code in onResume() or start your new activity with startActivityForResult() and then add onActivityResult() in your main activity.
http://developer.android.com/reference/android/app/Activity.html
________________________________
http://ron-droid.blogspot.com
Thank you Rigman. I'll give that a go.
Sent from my HTC Desire using XDA App
Related
My limited programming experience does not reach into the realm of android, as evidenced by the title of this thread. So I figured I'd ask for help.
Here is what I'm trying to do: Tie and activity to the Simi Clock launcher.
Unfortunately, it only lists apps in the launcher options, so I was wondering if there is an easy way to make an app out of an activity.
Any help is greatly appreciated.
Do you mean how do you make an app with an activity at all, or how to use it with the clock you mentioned?
A new app can be easily created using the ADT Plugin for Eclipse, a great thing to have. From there all you have to do is make a new class that extends Activity class.
You can use intents to run portions of other apps, but I am not sure if I quite understand what you mean.
roflha said:
Do you mean how do you make an app with an activity at all, or how to use it with the clock you mentioned?
A new app can be easily created using the ADT Plugin for Eclipse, a great thing to have. From there all you have to do is make a new class that extends Activity class.
You can use intents to run portions of other apps, but I am not sure if I quite understand what you mean.
Click to expand...
Click to collapse
Hehe, and I'm not sure I understand what you mean, but that's because I know diddly-squat about this stuff.
Let me be more descriptive:
- Let's say I have a widget, for example Beautiful clock, which allows me to to launch an app upon clicking on the clock numbers.
- I also have a launcher which allows me to make shortcuts directly to activities, for example wifi toggle. That acts like an app or widget if placed on a home screen.
- Now, I would like to be able to invoke that "wifi toggle" or other activity by clicking on the clock widget numbers. However, my clock widget only lists apps in "launch-able" options. Hence the dilemma.
Did that make any sense?
Yeah, I think I see what you're saying.
Well one thing worth noting is that the clock widget is most likely not pulling its list of possible applications based off of the ones you have links to or the ones in your drawer. What I am guessing is it using something called an Intent that allows it to filter for all of the apps that have a launch-able intent Your shortcut most likely doesn't have that.
What you could try doing is, since you were asking about Activities, is create a simple app that, when run, redirects you to the WiFi settings. All the code would be for such an Activity is
Code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
startActivity(intent);
}
Like the attached apk... lol. Install it and try to map weather to it.
roflha said:
Yeah, I think I see what you're saying.
Well one thing worth noting is that the clock widget is most likely not pulling its list of possible applications based off of the ones you have links to or the ones in your drawer. What I am guessing is it using something called an Intent that allows it to filter for all of the apps that have a launch-able intent Your shortcut most likely doesn't have that.
What you could try doing is, since you were asking about Activities, is create a simple app that, when run, redirects you to the WiFi settings. All the code would be for such an Activity is
Code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent("android.settings.WIFI_SETTINGS");
startActivity(intent);
}
Like the attached apk... lol. Install it and try to map weather to it.
Click to expand...
Click to collapse
Thanks for the help. I love this place!
Could someone help me add a m player and a setonclicklistener in a fragment. I have a couple of sound bite apps and I am trying to put them together in a Viewpager. I have the layout all set up, but im not sure on how to have the m player to the fragment. Thanks.
Sent from my SCH-I535 using Tapatalk 2
Set an onClickListener by using the setOnClickListener() method in the onCreateView() method.
If you set the onClick attribute in the xml, it will look for the method in your Activity.
The MediaPlayer requires a Context, right? Pass your Activity which you can get by calling getActivity().
u can use fragmentpagerapteradapter
to assign fragment as viewpager child...
My app uses the ActionBarCompat and NavigationDrawer, which begs the question of how is one supposed to structure the navigation? I see two options:
1) Use a single Activity and swap out Fragments.
2) Use multiple Activities, and transition between them.
The latter seems to be the correct way, however this means that each Activity must get and build the ActionBar and NavigationDrawer when called from another Activity.
How will this affect my transition animations? If I have a left-to-right transition effect when a navigation item is clicked, will it transition the entire Activity or everything below the ActionBar?
The former seems fraught with issues. A single .java class file could get really heavy and difficult to manage.
But while we're on the subject of Fragments, please consider this situation and school me on proper Fragment management:
A blank Activity with just a LinearLayout attaches a new Fragment to it that contains a Button. Inside the Fragment class, this button gets an onClickListener and when the button is clicked, another of the same kind of Fragment should be attached to the LinearLayout inside the Activity.
A) Should the Fragment class communicate to the Activity that a new Fragment should be attached? This could be done with a custom public interface and the callback being executed within the onClickListener in the Fragment class.
B) Or, should the Fragment handle attaching the new instance inside the onClickListener, making the Activity work less? By simply bridging the clicked Button and calling .getParent() until the LinearLayout is reached, then attaching it there.
The correct way is the former. You should use fragments with the navigation drawer. If you use activities you are going to setup the navigation drawer every new activity. You should open other fragments from the activity and not from the fragment itself. I believe their is a tutorial on the android developer site that explains this in depth. A quick Google search for "android fragment to fragment communication" or something like that should get you to it. I'll try and find a link later when I am on my computer if you don't find anything
Sent from my Nexus 7 using XDA Premium HD app
Hi
In the book that I am reading there is a paragraph about teaching the Intent concept :
"" An intent generically defines an intention to do some work. Intents encapsulate several
concepts, so the best approach to understanding them is to see examples of their use.
You can use intents to perform the following tasks:
Broadcast a message.
Start a service.
Launch an activity.
Display a web page or a list of contacts.
Dial a phone number or answer a phone call.
Intents are not always initiated by your application—they’re also used by the system to
notify your application of specific events (such as the arrival of a text message).
Intents can be explicit or implicit. If you simply say that you want to display a URL, the
system decides what component will fulfill the intention. You can also provide specific
information about what should handle the intention. Intents loosely couple the action
and action handler. ""
I completely understand the paragraph except the final portion that I underlined it .
What does that mean ???
Please explain it for me .
What is action and action handler ???
Thanks for your help
The action is what you want to do (e.g.: show a website) and the action handler is the app that can handle the action (e.g: the browser app).
So a intent combines that two things: the information "show a website" and the app that can do what you want (the browser)
@EmptinessFiller is right .
Suppose you want to open an image generated by your app. Then you would have the following options:-
Option 1
Implement a custom Activity and send an intent to start it so the image can be processed.
Option 2
Launch an intent to any other app like the gallery app to handle the intent.(Display your image)
Give a thanks if you think this post helped you!
Sent from my Nexus 4 using XDA Premium 4 mobile app
The 'loosely' in my opinion refers to the possibility to either exactly define who you want to do your action (an explicit intent) but you can as well just leave open who does that (an implicit intent), then you will get that well known 'complete action using...' dialogue
So action and its handler can but dont have to be coupled inside the intent
---------------------------------
Phone : My new Nexus 4!
OS:
Pure KitKat 4.4.2 stock, no root, no mods (but only for the first time ;D)
---------------------------------
Gesendet von Tapatalk
The app I'm developing has a number of master-detail scenarios using the standard design-pattern. In a detail activity I need to indicate to the listview activity that an update/delete has occurred. This so that I can update the list using the adapter's setNotifyChange method. The list activity uses a callback to its parent activity where a decision is made about type of device ie; Is it a 'twoPane' scenario? This activity then calls the Fragment passing a reference to the selected row to the detail activity so it can be updated/deleted. I've tried creating a callback from this detail activity to the listview activity but this doesn't work. I assume that is because the detail activity was not invoked directly from the list activity, but from the activity containing the device decision. Maybe I'm missing something obvious. but does anyone have any suggestions for a solution.
Thanks for any help.
javabiker said:
The app I'm developing has a number of master-detail scenarios using the standard design-pattern. In a detail activity I need to indicate to the listview activity that an update/delete has occurred. This so that I can update the list using the adapter's setNotifyChange method. The list activity uses a callback to its parent activity where a decision is made about type of device ie; Is it a 'twoPane' scenario? This activity then calls the Fragment passing a reference to the selected row to the detail activity so it can be updated/deleted. I've tried creating a callback from this detail activity to the listview activity but this doesn't work. I assume that is because the detail activity was not invoked directly from the list activity, but from the activity containing the device decision. Maybe I'm missing something obvious. but does anyone have any suggestions for a solution.
Thanks for any help.
Click to expand...
Click to collapse
After thinking more about this problem I came to the idea that creating a callback path thru the various classes involved was worth trying. Will publish the results.
Have you ever used an EventBus? Like Otto from Square? https://square.github.io/otto/
There's also, https://github.com/greenrobot/EventBus. I prefer Otto.
You just register your Fragments/Activities on onResume and unregister on onPause.
Thanks for the suggestion. Coincidently, I'd been looking at Otto without realizing its applicability to this issue. Will give it a try.
Sent from my SAMSUNG-SGH-I337 using XDA-FORUM, powered by appyet.com