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!
Related
Hi.
I've been researching for many days. and i am really out of ideas.
First. I am new to all this.
Okay. my project:
I have:
- 1 Activity
- 1 Widget
So. my app is the widget itself. when you click the widget, it opens up the activity, the activity consists of a + and - button and a textview. the textview is on 0. when you click on +, you add up +1 to the textview and vica versa with the -.
So, what i want, in the activitys "onPause()", i want it to save the value and transfer it to the widget, i tried to send a broadcast, but that didnt work properly (i wanted to save the value in a hidden textview, but appwidget cant read values of TextViews -.-').
Also i tried some sql stuff.. didnt work either (appwidget doesnt support?)
Tried so save as a file on sd, didnt work (appwidget doesnt support?)
I couldnt use the broadcast thing because my app is made like this:
appwidget:
public void onUpdate(Context context,AppWidgetManager mgr,int[] appWidgetIds){
SetUp(context, mgr, appWidgetIds);
}
public void SetUp(Context c, AppWidgetManager mgr, int[] appWidgetIds){
//do stuff.....
}
public void onReceive(Context context, Intent intent) {
//If i get the number here, i cant really do anything with it, because i cant really save my value anywhere?
}
Bump. no one can help ?
I tried with the intent.putextra, but wont work.
If anyone wants to help me at msn, pm me. (eventually lightly paid)
Hi
Have you figured how to do it yet? I'm having the exact same problem and I'm unable to find any kind of solution.
Thank you!
Hi,
I have been trying to get to grips with Android.
First off I guess, any good books you can recommend? I have Hello, Android which has some good examples, but some of the things leave me a little cold in that it seems overly simplistic and then seems to fail to pick up on some latter crucial points, not least about creating custom adapters.
Anyhow, back to the questions.
Firstly, various devices, like the Samsung Galaxy S uses a "blue" summary line in its settings menus. Looks good. But if you want to mimic that style outside of a summary menu, is it possible to get details of system colours?
Secondly, in terms of icon design, tab icons in as defined in the Android SDK seem to suggest using a Grey icon for off and a white icon for on. This seems to bit a bit foolish when the tabs are white.... and most of the other programs I've seen that use tabs have Grey icons for on and white icons for off! Thoughts?
Third, back to this book, one of the examples it gives, is a way to load data from a SQL database using Cursors and SimpleAdapters. Im guessing if I want anything more than a relatively simple list and data pulled from the database, that Im going to need to use a CustomAdapter.
In terms of these cursors though, some of the code does this in the onCreate:
Code:
Cursor cursor
CustomDatabaseHelper test = new CustomDatabaseHelper(this);
try {
cursor = getData();
showData(cursor);
} finally {
test.close();
}
I think I found a couple of problems with that... The CustomDatabaseHelper and Cursor are both local to the onClick method and therefore if I need to access these via a Buttons onClick Im stuffed unless I make them private/public to the class. I don't know the best way around this TBH, what would you suggest? I guess I could define another CustomDatabaseHelper in the onClick method, but Im not sure whether it is a good idea to keep opening all these references.
Plus as well in onClick, you can't give a context of "this" because it's it's not a context there its an OnClickListener?
Code:
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
}
And there must be a better way of refreshing the data set? I've tried cursor.notify, test.notify and globalising the adapter and doing adapter.notifyDataSetChanged(); things still don't refresh.
Im going to guess this is a pretty basic and common issue for newcomers trying to understand this that super context intent.
I think Im getting there, Im just trying to get a bit of background to a few of the basic issues Im having a bit of trouble with and find out what the best way to handle the issues are.
Oh, the showData function (which I call after any data change at the moment), does this:
Code:
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.test_item, cursor, Columns, TO);
I think that'll do for now, as my next issues are about SQL, Dates and Formatting.
Thanks
Simon
I think my problem stems around this book of mine... I can do a "notifyDataSetChanged()" on the adapter provided I don't do the "test.close" as above.
This suggests to me the DB Helper should be open across the activity lifetime.
Is that right?
I have multiple widgets provided by one app, and thus multiple classes that extend AppWidgetProvider. The idea is that every widget contains a Button, which starts a Service when pressed. This Service runs a bit of code and then stops. Now for the problem: for example, I have a Widget1a and a Widget1u. These widgets look like each other, but each widget does a slightly different thing. If I place a Widget1a on the homescreen and press it, a Service is started and the code that this Service should run is run, as it should be. Now I place a Widget1u on the homescreen, and suddenly Widget1a stops working and doesn't do anything when I press it. If I place a second Widget1a on the homescreen both Widget1as work again, but now Widget1u is disabled and doesn't respond when I press it. In short: it seems that at any particular time only one type's code works when it is pressed (and if there are multiple instances of the same type on the homescreen all of these instances will work, but no instances of any other widget of my app will do anything when pressed).
The code in the AppWidgetProvider of each widget is pretty basic. It merely contains an overrided onUpdate-method. It creates an Intent to start a Service that I previously created, this is then used to create a PendingIntent which is used by setOnClickPendingIntent to make sure it can be activated by a Button in the widget. Each widget makes, when its Button is pressed, a slightly different Intent so that a certain Service is executed slightly differently. So this only works for the instances of 1 widgettype at a time, namely those of which an instance was added to the homescreen most recently.
Why do all my app's other widgets stop working when I add a widget of a different type to my homescreen? Does anyone know more about widgets or how I can make sure that each widget keeps doing its job when I add a new one from the same app to the homescreen?
Here is the onUpdate method of one of my AppWidgetProviders for one of my widgets. All widgets operate similarly and I know I used a lot of copypasting which is a bad programming habit but it didn't seem to really want to work otherwise.
Code:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// Create an intent to launch the service
Intent serviceIntent = new Intent(context, SendService.class);
//I just put some extra data here to be used by the Service which wil eventually get this Intent and thus the data inside
serviceIntent.setData(Uri.parse("uri::somethingrandomandunique"));
serviceIntent.putExtra("Lamp", "1a");
// PendingIntent is required for the onClickPendingIntent that actually
// starts the service from a button click
PendingIntent pendingServiceIntent =
PendingIntent.getService(context, 0, serviceIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
// Get the layout for the App Widget and attach a click listener to the
// button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget1a);
views.setOnClickPendingIntent(R.id.button1a, pendingServiceIntent);
// super.onUpdate(context, appWidgetManager, appWidgetIds);
ComponentName componentName = new ComponentName(context.getPackageName(), Widget1a.class.getName());
appWidgetManager.updateAppWidget(componentName, views);
}
So what am I doing wrong?
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
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