Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4336694
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:50:31+00:00 2026-05-21T10:50:31+00:00

In my Activity class implements UINotifier that is used to notify the Activity class

  • 0

In my Activity class implements UINotifier that is used to notify the Activity class on call of a TimerTask object. In my doInBackground(), I call my function located in ASyncTask class (connectTask) only. onPostExecute is executed and in last, I call a method “ReConnect()” that is located in my Activity class.
The code and its flow is :

// OF Interface UINotifier
@Override
public void notifyUI() {
    Log.i(TAG, "GOT MESSAGE FROM MonitorConnection");
    monitorTimer.cancel();
    Log.i(TAG, "Preparing to Start");
    PrepareToStartToConnect();
    //publishProgress(4);
    int status = 1;
    if (status == 1 || status == 2)
        ReConnect();
}

// Called on "Connect" button
private void ConnectClicked() {
    Log.i(TAG, "Inside Connectclicked");
    if (isConnectEligeble()) {
        Log.i(TAG, "isConnectionEligible = true");
        currentState= CONNECTING;
        connectTask = new ConnectTask();
        Log.i(TAG, "CReated ins of ConnectTask");
        connectTask.execute("");
    }
}

private void ReConnect() {
    connectTask = null;

    if (HttpUtilities.checkInternetConnection()) {
        Log.i(TAG, "ABOUT TO RE-CONNECT");
        ConnectClicked();
    } else {
        Log.i(TAG, "No Interne Mesage");
        mMessage.setText(R.string.NO_INERNET);
    }
    return;
}

private void PrepareToStartToConnect() {
    monitorTimer = null;
    monitorConn = null;
    // Make all vars, objects to null   
}

// Start TimerTask & Timer object
private void StartTimer() {
    Log.i(TAG, "Into Start Timer");
    monitorConn = new MonitorConnection(this);   // new MonitorConnection(connectTask);
    monitorTimer = new Timer();
    monitorTimer.schedule(monitorConn, 0, 30000);
}


/**
 * ConnectTask  AsyncTask class that handles all activities to get connected to the server
 */
private class ConnectTask extends AsyncTask<String, Integer, Boolean> implements UINotifier {
    private ProgressDialog dialog = null;
    private UServer us = null;
    private VPNServer vs = null;
    private ConfigData cd = null;
    String serverHost = "", errorMsg = ""; 
    private int status = -1; // 0 Connected  1 = ReConnect  2 = Failed to Connect

    public ConnectTask() {
        dialog  = new ProgressDialog(StartUltimate.this);
        us  = servers.get(selectedRowIndex);
        vs = us.getVpnServer(selectedProtocol, selectedPort);
        serverHost = us.getServerHost();
    }

    private void disposeAll() {
        // Dispose all objs
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        Log.i(TAG, "Into onPostExecute()");
        if (result == false)
            mMessage.setText(errorMsg);
        else
            mMessage.setText("");
        dialog.dismiss();
        // Clean up all variables of the object
        disposeAll();
        Log.i(TAG, "FINISHED onPostExecute()");
        // Go out of AsyncTask and have control to other method of Activity class
        StartTimer();
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        selectedServerHost = serverHost.substring(0, serverHost.indexOf('.'));
        dialog.setCancelable(false);
        dialog.setIcon(R.drawable.icon);
        dialog.setTitle("Progessing...");
        dialog.setMessage(String.valueOf(R.string.ui_activity_authenticating));
        dialog.show();
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
        // Set all updates to UI
        return;
    }

    @Override
    protected Boolean doInBackground(String... params) {
        Log.i(TAG, "Into doBackground...");
        ......
        Log.i(TAG, "Starting Connect.....");
        StartConnect();

        return true;
    }

    @Override
    public void notifyUI() {
        Log.i(TAG, "GOT MESSAGE FROM MonitorConnection");
        monitorTimer.cancel();
        Log.i(TAG, "Preparing to Start");
        PrepareToStartToConnect();
        publishProgress(4);
        status = 1;
        if (status == 1 || status == 2)
            ReConnect();
    }


    private void StartConnect() {
        // This is empty right now      
    }
}   // END OF ConnectTask class

StartTimer is called, and MonitorThread notifies Activity class and that calls ReConnect which inturn calls ConnectClicked. In ConnectClicked,
connectTask = new ConnectTask(); is where I get this exception and the log :

04-15 17:09:07.501: INFO/Ultimate VPN:(364): Starting Connect.....
04-15 17:09:07.501: INFO/Ultimate VPN:(364): Into onPostExecute()
04-15 17:09:07.501: INFO/Ultimate VPN:(364): FINISHED onPostExecute()
04-15 17:09:07.501: INFO/Ultimate VPN:(364): Into Start Timer
04-15 17:09:07.542: INFO/MON CONN(364): Into StartMonitor
04-15 17:09:07.542: INFO/MON CONN(364): Into checkConnection
04-15 17:09:07.671: WARN/InputManagerService(69): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4073b170
04-15 17:09:08.252: INFO/System.out(364): MonitorConnection : Notifing the GUI
04-15 17:09:08.262: INFO/Ultimate VPN:(364): GOT MESSAGE FROM MonitorConnection
04-15 17:09:08.262: INFO/Ultimate VPN:(364): Preparing to Start
04-15 17:09:18.322: INFO/Ultimate VPN:(364): ABOUT TO RE-CONNECT
04-15 17:09:18.322: INFO/Ultimate VPN:(364): Inside Connectclicked
04-15 17:09:18.322: INFO/Ultimate VPN:(364): isConnectionEligible = true
04-15 17:09:18.331: WARN/dalvikvm(364): threadid=11: thread exiting with uncaught exception (group=0x40015560)
04-15 17:09:18.351: ERROR/AndroidRuntime(364): FATAL EXCEPTION: Timer-0
04-15 17:09:18.351: ERROR/AndroidRuntime(364): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at android.os.Handler.<init>(Handler.java:121)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at android.app.Dialog.<init>(Dialog.java:101)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at android.app.AlertDialog.<init>(AlertDialog.java:63)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at android.app.ProgressDialog.<init>(ProgressDialog.java:80)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.StartUltimate$ConnectTask.<init>(StartUltimate.java:386)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.StartUltimate.ConnectClicked(StartUltimate.java:324)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.StartUltimate.ReConnect(StartUltimate.java:340)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.StartUltimate.notifyUI(StartUltimate.java:316)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.MonitorConnection.setConnected(MonitorConnection.java:43)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.MonitorConnection.checkConnection(MonitorConnection.java:69)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.MonitorConnection.StartMonitor(MonitorConnection.java:61)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at orange.android.vpn.MonitorConnection.run(MonitorConnection.java:52)
04-15 17:09:18.351: ERROR/AndroidRuntime(364):     at java.util.Timer$TimerImpl.run(Timer.java:284)
04-15 17:09:18.382: WARN/ActivityManager(69):   Force finishing activity orange.android.vpn/.StartUltimate

Any idea why I get this error ? How do I solve it ? I tried handling the UINotifier in ConnectTask class instead of Activity class. But the onPost is called immediately after StartConnect() , despite StartTimer was added to it and that thread was already running. Then also the doInBackground stops, so I managed it this way. But both the ways I get error. In other case I get … Looper…. exception.

Any help is highly appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:50:32+00:00Added an answer on May 21, 2026 at 10:50 am

    I would get rid of the UINotifier (custom implementation) and look at using the out-of-the box Handler mechanism in Android to notify the UI.

    See How to get XML using AsyncTask and Timer? for a similar implementation.

    Also, see the Painless threading article here : http://developer.android.com/resources/articles/painless-threading.html for more information about threading (and Handlers)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a class to handle all database-activity in my application, and so
I have an activity that has a TabHost containing a set of TabSpecs each
i have created a workflow activity that do give the item creater of a
I have a web-based application that notifies users of activity on the site via
The activity monitor in sql2k8 allows us to see the most expensive queries. Ok,
Sampling with Activity Monitor/Instruments/Shark will show stack traces full of C functions for the
Is there any way to view the activity log for the integrate SourceSafe inside
In my Mac OS X Activity monitor it lists each process id for each
I need to generate a list of activity from multiple tables in order of
I have a need to do auditing all database activity regardless of whether it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.