I managed to figure it out. You were right in that it didn't have
anything to do with RemoteViews or RemotableViewMethod.
Instead, my problem was that in my onClick method for my start button,
I was using the variable mChronometer, which was null, and so threw an
exception.
The bug was located in the onCreate() method of my activity.
Specifically, I had:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, onCreate());
mChronometer = (Chronometer)findViewById(R.id.Chronometer);
mStartStop = (Button)findViewById(R.id.StartStopButton);
mResetLap = (Button)findViewById(R.id.ResetLapButton);
setContentView(R.layout.stopwatch);
}
But android didn't like this. findViewById() doesn't work correctly
unless it's called after setContentView(), so it was returning null
for all my fields and giving me the error.
Easy fix, just move setContentView() up, like so:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, onCreate());
setContentView(R.layout.stopwatch);
mChronometer = (Chronometer)findViewById(R.id.Chronometer);
mStartStop = (Button)findViewById(R.id.StartStopButton);
mResetLap = (Button)findViewById(R.id.ResetLapButton);
}
Thanks for your help!
Daniel Bostwick
On Nov 3, 6:56 pm, Mark Murphy mmur...@commonsware.com wrote:
bostwick wrote:
The included Chronometer widget doesn't quite have the functionality I
wanted, so I copied its code into my own package.
The source code to Android is not necessarily designed to be pulled out
and used in isolation elsewhere. Some classes will work that way (e.g.,
I have cloned AsyncTask and MatrixCursor), but others will not because
they have dependencies on other open-source-but-not-in-the-SDK classes
and methods.
Looking through the android source, you can see stock widgets using
theRemotableViewMethodall over the place, but for some reason, my
code can't.
That is probably used by the firmware build process.
So, my question is this: What can I do to enable the
RemotableViewMethodannotation in my custom widgets?
Most likely, you can't.
Is there
something I should be doing differently in order to code custom
widgets?
Well, your underlying problem didn't make it into your paste. You are
failing on a NullPointerException (line #42 of the paste), and you need
to track that down.
AFAIK, theRemotableViewMethodannotation will not affect you if you are
using a widget in an activity.
I know that part of the problem is just my lack of experience with the
Android SDK, and I don't fully understand what the RemoteViews class
does or why it's needed, and the two sentence description in the API
docs doesn't help much there. If someone could explain just the
logistics of this class, that would also be helpful.
Mostly, in terms of the SDK, RemoteViews is used for app widgets --
those doodads you can put on the home screen. Since the home screen runs
as its own process, it can't execute your code. Instead, via
RemoteViews, you effectively serialize a bunch of UI operations that get
sent from your own process to the home screen for execution. UI widgets
(android.widget.*) that work with RemoteViews get the
@android.view.RemotableViewMethodto indicate what can and cannot be
used in this fashion, AFAICT.
--
Mark Murphy (a Commons
Guy)http://commonsware.com|http://twitter.com/commonsguy
_Android Programming Tutorials_ Version 1.0 In Print!
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en