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
Related
Greetings,
I have some calculations on the main view based on some data you set in the options view. What I want to do is, when you go to the options view and change some data then click SAVE(this throws you back to the main view) that the calculations will have been made already based on the new data. The calculations are done by a service and are called once when you first open the app, so currently you need to close and reopen the app to see the new calculations.
help appreciated
I'm guessing you have a main activity for your "main view", from which you launch an options activity? If so you can simply startActivityForResult(...) from the main activity. When the user clicks SAVE just have the activity setResult(...) with an intent that contains the necessary data. Then override the onActivityResult(...) method in your main activity to handle that intent with the new data. There are also API's for activities specifically designed to manage application settings.
Also, remember that onResume() is called after onCreate() even when an activity first launches. So you could move the code that performs the calculations from onCreate() to onResume().
Hope this helps
I'm developing a simple android application using the TabActivity.
This Activity adds 3 tabs, each one with its own activity.
The problem is: when I tap each tab, the system calls onDestroy of the current activity. So, when I tap the first activity again, all the state of private fields are gone, its like it has created a new instance every time I change tabs.
I was searching around about this, and looking on the samples, but I guess that the default behavior is to keep the activity instances paused when the tab is not current.
Anyone have an idea of what I'm missing?
Thanks.
That is by design. You need to override onSaveInstanceState() and onRestoreInstanceState() in your activity class. You can store/retrieve state data there, or retrieve it int the Bundle passed into OnCreate(). See:
http://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle)
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!
Hi,
I'm developing my first app and i have some problems. My app has an activity that shows a different items of a list depending of user location. So, i created a service that is also a location listener and is updating distance data of items when "onLocationChanged(Location l)" is called from location provider (gps o network).
To start the activity of this list, i check location listener can be asigned to one location provider and wait for new location data. Namely, I wait in a loop checking a variable named "isnew" that i read from a global state class instantiated in manifest. I get this object calling to getapplication() if its and activity and getApplicationContext() if its from a service.
This variable is writed from LocationListener service and readed from activity in a loop. When LocationListener onLocationChanged method is called, this method writes this global variable with a true. The loop in the activity is like:
while(!this.getActivity().isNew){}
while isNew is false the activity waits looping. The problem is that activity never leaves the loop even when onLocationChanged is called. What i'm doing wrong? Thanks.
Have you looked through nikwen's debugging guide? The same techniques can be applied to debugging when no crashes are happening.
http://forum.xda-developers.com/showpost.php?p=42601921
If you still need help, as post 9 says on the debugging guide, we need to see your code.
Did you use LocationManager? You need to use LocationManager and LocationListener together
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