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 6320673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:01:00+00:00 2026-05-24T16:01:00+00:00

I am new to android widget.I did sample application , that want to show

  • 0

I am new to android widget.I did sample application , that want to show time .How to call widget from activity:

I tried like this but It say Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.weather/com.weather.CurrentCity}; have you declared this activity in your AndroidManifest.xml?

   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.weather"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="Weather">
    <!-- Broadcast Receiver that will process AppWidget updates -->
    <receiver android:name=".CurrentCity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
        android:resource="@xml/hello_widget_provider" />
    </receiver>

      <activity android:name=".WeatherActivity"
              android:label="Weather Application">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

<uses-permission android:name="android.permission.INTERNET" />

and my initail activity :

 public class WeatherActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent showContent = new Intent(getApplicationContext(),CurrentCity.class);
    startActivity(showContent);
}

and my widget activity:

  public class CurrentCity extends AppWidgetProvider {

public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1,
            1000);

}

private class MyTime extends TimerTask {
    RemoteViews remoteViews;
    AppWidgetManager appWidgetManager;
    ComponentName thisWidget;
    DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());

    public MyTime(Context context, AppWidgetManager appWidgetManager) {
        this.appWidgetManager = appWidgetManager;
        remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.current_weather);
        thisWidget = new ComponentName(context, CurrentCity.class);
    }

    @Override
    public void run() {
        remoteViews.setTextViewText(R.id.country,"Time = " + format.format(new Date()));
        appWidgetManager.updateAppWidget(thisWidget, remoteViews);
    }
}

}

and I have created main.xml & current_weather.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" >

<TextView android:id="@+id/country" 
          android:text="TextView" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_margin="10dp"
          android:textColor="@color/solid_yellow"
    ></TextView>


</RelativeLayout>

and I created hello_widget_provider.xml.xml in the res/xml/hello_widget_provider.xml

  <?xml version="1.0" encoding="utf-8"?>
  <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dip"
android:minHeight="72dip"
android:updatePeriodMillis="10000"
android:initialLayout="@layout/main"
  />

Please help me

Thanks in advance

  • 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-24T16:01:03+00:00Added an answer on May 24, 2026 at 4:01 pm

    What you are trying to do is effectively impossible. You do this:

    Intent showContent = new Intent(getApplicationContext(),CurrentCity.class);
        startActivity(showContent);
    

    You can not invoke a widget this way: a widget does not have an Activity you can show.

    You need to follow very closely the tutorial at http://developer.android.com/guide/topics/appwidgets/index.html: there is really no succinct way I can think of to convert your code into a working widget, but the guide has everything you need to know/do to make a working widget.

    EDIT: note that your widget must be added to the widget container (probably the home screen) and can not be added programmatically. The user of the Android device must do it manually.

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

Sidebar

Related Questions

Suppose I am creating an Android application that's like an SMS app. The requirements
Hi I'm new to android world.Iam working on an application that supports multiple screen
I know that eclipse can do this, can Intellij via the new Android support
I'm new to Android app development and I would like to ask something. I
I am absolutely new to the Android platform and have been building an application
I would like to write an android app that basically layers an overlay on
I am new to android,actually this is my second program.I am programming from last
package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity {
import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button;
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html

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.