Problems writing a C2DM service (InstantiationException).

by Cristian Udrea » Sat, 12 Feb 2011 06:07:38 GMT


Sponsored Links
 Hello everybody.
I'm trying to implement a C2DM service over a barebones "hello world"
application with two buttons.
At first I used a BroadcastReceiver, but it has a 10 second execution
limit and a few other limitations,
so I thought it would be better to use the IntentService approach
(google's C2DM samples).
I picked the crome-to-phone example.

The problem is that  when executing the following lines:

    static void runIntentInService(Context context, Intent intent) {
        if (mWakeLock == null) {
            // This is called from BroadcastReceiver, there is no
init.
            PowerManager pm =
                (PowerManager)
context.getSystemService(Context.POWER_SERVICE);
            mWakeLock =
pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                    WAKELOCK_KEY);
        }
        mWakeLock.acquire();

        intent.setClassName(context,
"com.example.helloandroidc2dm.C2DMReceiver");
        context.startService(intent); <=== HERE
    }

the JVM throws what seems to be a recursive InstantiationException.

Normally, that would be because of abstract methods, but after
changing the class to no longer
be an abstract class, it still happens.

Does anyone have (at least) a pointer for where I should start
debugging ?

Thanks in advance.

-- 



Other Threads

1. WebView not working

I am trying to get a simple webview working for use in a bigger
program. I can't even get a sample off the ground. I just get a black
screen on my phone (2.0) with a typical title bar at the top that
comes by default. Please help.

This is my HelloWebView.java:

package com.pv.hellowebview;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class HelloWebView extends Activity {
    /** Called when the activity is first created. */
        WebView webview;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl("http://www.google.com");
    }
}


here is my layout main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>

and finally here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.pv.hellowebview"
      android:versionCode="1"
      android:versionName="1.0">
      <uses-permission android:name="android.permission.INTERNET" />
    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".HelloWebView"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />

</intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="5" />
</manifest>

--

2. Ajax comunication between web browser and service

Hi,

We need to add an extension to the browser.

Sine there is not support for Netscape style plugin in the browser we
would like to use a custom URL scheme (myapp://) to communicate from
any web page with our app/service.

Is that possible with Android ?

We did some basic testing and

<a href="myapp://mysettings">GO</a> <br>

Launches my app

<a href="javascript:$.get('myapp://mysettings');">AJAX</a> <br>

But does nothing

Thanks,

-- 

3. Problem in framing the request to Exchange server for Email search

4. AVDs

5. Playing RTSP or m3u with MediaPlayer

6. Playing video with an alpha channel

7. How to generate system.img from Froyo for HTC HERO G2