Home Forum

Apps Activity must be exported....

I've developed a relatively basic app (or at least tried to), but have not managed to get it to run. I had one set of error messages, left it a while, needed to upgrade the Android App Development Studio, and now have a new error!

If I try to run it, I get the following "The Activity must be exported or contain an intent-filter". Could anyone please advise what this means? Do I need to set up some kind of backup file, or save something in the right location?

Happy to provide more information to anyone who can help me.
 

Related:

#1 HH12321, Jul 17, 2017
Need to see:-

1. Manifest file
2. Code for Activity
3. The complete error message, from the log file

Please put all XML and code in between [code][/code] tags

Thanks!
 
#2 LV426, Jul 17, 2017
Thanks so much for such a speedy response! I've just tried hunting around for the manifest file (it's been a little while) and what I thought it was apparently has an illegal file type to upload here. Could you possibly enlighten me? What's the likely suffix? And where should it be in the file structure?

Please let me know if the following is in the wrong format or if I've done something wrong. Maybe if the manifest file has disappeared that could be the whole issue!

The error message is:
17:02 Error running ActivityEnergyUsage: The activity must be exported or contain an intent-filter

The code is as follows:

Code (Text):
  1.  
  2. ackage com.example.hannahhoward.carboncardiobalancing;
  3.  
  4. import android.content.Intent;
  5. import android.net.Uri;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.ArrayAdapter;
  10. import android.widget.Spinner;
  11.  
  12. import com.google.android.gms.appindexing.Action;
  13. import com.google.android.gms.appindexing.AppIndex;
  14. import com.google.android.gms.appindexing.Thing;
  15. import com.google.android.gms.common.api.GoogleApiClient;
  16.  
  17. public class ActivityEnergyUsage extends AppCompatActivity {
  18.  
  19.     /**
  20.      * ATTENTION: This was auto-generated to implement the App Indexing API.
  21.      * See https://g.co/AppIndexing/AndroidStudio for more information.
  22.      */
  23.     private GoogleApiClient client;
  24.  
  25.     public void click3(View v){}
  26.     Intent goToMainActivity=onNewIntent();
  27.         goToMainActivity.setclass(this,MainActivity.class)
  28.     ActivityEnergyUsage(goToMainActivity){
  29.         finish();}
  30.  
  31.         protected void onCreate(Bundle savedInstanceState) {
  32.         super.onCreate(savedInstanceState);
  33.         setContentView(R.layout.activity_energy_usage);
  34.         // ATTENTION: This was auto-generated to implement the App Indexing API.
  35.         // See https://g.co/AppIndexing/AndroidStudio for more information.
  36.         client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
  37.     }
  38.  
  39.     Spinner spinner_energyactivity = (Spinner) findViewById(spinner_energyactivity);
  40.     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.energyusage_array, android.R.layout.simple_spinner_item);
  41.     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  42.     spinner.setAdapter(adapter);
  43.     Spinner spinner_duration = (Spinner) findViewById(spinner_duration);
  44.     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.duration_array, android.R.layout.simple_spinner_item);
  45.     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  46.     spinner.setAdapter(adapter);
  47.     /**
  48.      * ATTENTION: This was auto-generated to implement the App Indexing API.
  49.      * See https://g.co/AppIndexing/AndroidStudio for more information.
  50.      */
  51.     public Action getIndexApiAction() {
  52.         Thing object = new Thing.Builder()
  53.                 .setName("ActivityEnergyUsage Page") // TODO: Define a title for the content shown.
  54.                 // TODO: Make sure this auto-generated URL is correct.
  55.                 .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
  56.                 .build();
  57.         return new Action.Builder(Action.TYPE_VIEW)
  58.                 .setObject(object)
  59.                 .setActionStatus(Action.STATUS_TYPE_COMPLETED)
  60.                 .build();
  61.     }
  62.  
  63.  
  64.  
  65.     }
  66.  
  67.     [USER=1021285]@override[/USER]
  68.     public void onStart() {
  69.         super.onStart();
  70.  
  71.         // ATTENTION: This was auto-generated to implement the App Indexing API.
  72.         // See https://g.co/AppIndexing/AndroidStudio for more information.
  73.         client.connect();
  74.         AppIndex.AppIndexApi.start(client, getIndexApiAction());
  75.     }
  76.  
  77.     [USER=1021285]@override[/USER]
  78.     public void onStop() {
  79.         super.onStop();
  80.  
  81.         // ATTENTION: This was auto-generated to implement the App Indexing API.
  82.         // See https://g.co/AppIndexing/AndroidStudio for more information.
  83.         AppIndex.AppIndexApi.end(client, getIndexApiAction());
  84.         client.disconnect();
  85.     }
  86.  
 
#3 HH12321, Jul 17, 2017 Last edited by a moderator: Jul 17, 2017
The manifest is an XML file called AndroidManifest.xml. It's in the root directory of your application structure, as described here

https://developer.android.com/guide/topics/manifest/manifest-intro.html

I edited your post to include the [code][/code] tags.
 
#4 LV426, Jul 17, 2017
Thanks - I have at least found the manifest file, so that is there, but it won't let me upload it here as it says that I can't upload a file with this extension.

I've copied and pasted the contents of the file below in case that's of use. Do you think that the issue could be that I had to copy my entire folder across and the folder it is now in is called: D:\HannahHoward\CarbonCardioBalancing_Test\app\src\main? Do I need to manually modify the manifest so that it references "_Test" within the <manifest package part?

Code (Text):
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3.  
  4. -<manifest package="com.example.hannahhoward.carboncardiobalancing" xmlns:android="http://schemas.android.com/apk/res/android">
  5.  
  6.  
  7. -<application android:theme="[USER=19691]@Style[/USER]/AppTheme" android:supportsRtl="true" android:label="[USER=696546]@String[/USER]/app_name" android:icon="[USER=22138]@Mipmap[/USER]/ic_launcher" android:allowBackup="true">
  8.  
  9.  
  10. -<activity android:name=".MainActivity">
  11.  
  12.  
  13. -<intent-filter>
  14.  
  15. <action android:name="android.intent.action.MAIN"/>
  16.  
  17. <category android:name="android.intent.category.LAUNCHER"/>
  18.  
  19. </intent-filter>
  20.  
  21. </activity>
  22.  
  23. <activity android:name=".ActivityEnergyUsage"/>
  24.  
  25. <!-- ATTENTION: This was auto-generated to add Google Play services to your project for App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
  26.  
  27.  
  28. <meta-data android:name="com.google.android.gms.version" android:value="[USER=1111536]@integer[/USER]/google_play_services_version"/>
  29.  
  30. <activity android:name=".ActivityWorkout"/>
  31.  
  32. </application>
  33.  
  34. </manifest>
  35.  
 
#5 HH12321, Jul 18, 2017 Last edited by a moderator: Jul 18, 2017
I'd start by removing the '-' characters at the beginning of some lines in your manifest.

Another question I have for you is - what's the full package name of your MainActivity class? I'd use that in the manifest, instead of just ".MainActivity"
 
#6 LV426, Jul 18, 2017
Thanks very much for your response LV426. I'm sorry to be so ignorant, however, the manifest was created directly when I built the xml files in the Android Studio. If I look in the text tab of the xml there then I don't have any of the '-' so I don't know how I can remove them from the manifest. Any suggestions?

Likewise, the reference to the activity has been set up directly within the studio. Does that make sense?

Thanks
 
#7 HH12321, Jul 19, 2017
You said that you'd copied your code from one place to another. That may well have screwed things up.
I would re-create the project again, within Android Studio. The new project wizard sets all this stuff up for you, and leaves you with a blank project skeleton, containing just the basic configuration files, such as the Manifest. Once the project structure is set up, you can proceed to populate it with your Activities and other code.
 
#8 LV426, Jul 19, 2017