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

  • SEARCH
  • Home
  • 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 9277453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:06:46+00:00 2026-06-18T17:06:46+00:00

I am trying to open an activity if the widget is clicked. But, when

  • 0

I am trying to open an activity if the widget is clicked. But, when i upload the package into my emulator, the activity opens automatically, even though it should open only if i click on the widget.

This is my manifest file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.NewsWidget"
    android:versionCode="1"
    android:versionName="1.0" >

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <service android:name=".UpdateWidgetService" >
        </service>

        <receiver android:name="MyWidgetProvider" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/widget_info" />
        </receiver>
         <activity
            android:name="com.example.NewsWidget.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleInstance" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".DetailedNewsViewer"
            android:label="DetailedNewsViewer" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk android:minSdkVersion="8" />

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

</manifest>

I have added the following code into my widget provider using the details from another question here (Launching activity from widget).

 Intent i = new Intent(); 
        i.setClassName("com.example.NewsWidget", "com.example.NewsWidget.MainActivity"); 
        PendingIntent myPI = PendingIntent.getService(context, 0, i, 0); 
        //intent to start service 

      // Get the layout for the App Widget 
      RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); 

      //attach the click listener for the service start command intent 
      views.setOnClickPendingIntent(R.id.update, myPI); 

      //define the componenet for self 
      ComponentName comp = new ComponentName(context.getPackageName(), MyWidgetProvider.class.getName()); 

      //tell the manager to update all instances of the toggle widget with the click listener 
      mgr.updateAppWidget(comp, views); 

What is the problem ?

  • 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-06-18T17:06:47+00:00Added an answer on June 18, 2026 at 5:06 pm

    I noticed that you are using PendingIntent.getService() but your calling an activity and not a service (per your manifest). Try using PendingIntent.getActivity() instead and see if your pendingIntent fires.

    Your main activity is loading when you run from eclipse, but edthethird is right, that is probably not related to your problem. It is just the default eclipse behavior to launch your main activity.

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

Sidebar

Related Questions

I am trying to make a simple program that could open a new activity
I'm trying the open a relative path in Ubuntu , but after opening the
I'm trying to open a zip file with jython using FileInputStream and ZipInputStream. But
I'm trying to make a widget to my app, but it doesnt update. I
I'm trying to open a dialog window, but every time I try to open
from my application i'm trying to open another one, using this code: package com.copag.lanceappli;
In my application I am trying to open an activity from a button in
I'm trying to open a new activity using this code: myListView.setOnItemClickListener(new OnItemClickListener() { @Override
In my application i am trying to open a dialog box when activity started
i am trying to open keyboard when i move to first activity to second

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.