I have started an Intent and asked it to go to the main activity, when it attempts it the app crashes.
Here is the code that tries to go to the main activity.
Intent i = new Intent(
".MAIN_ACTIVITY");
startActivity(i);
Here is the XML manifest for Main_Activity.
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
I'm still pretty new to this so any help and/or advice is of great value.
Write like this :
Intent i = new Intent(MainActivity.this, NewActivity.class);
startActivity(i);
Also you need to declare both activity class in manifest file like this:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".NewActivity"
android:label="#string/app_name" >
</activity>
For those, who come from Google, I was trying to pass large string in putExtra (over 90K Symbols) and my app was crashing because of that. The correct solution is either save the string to file or implement Singleton.
Here is the relevant link Maximum length of Intent putExtra method? (Force close)
as per your code: if i have create newActiviy in my project then:
i have to add that activity in android manifest file.
like:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<activity android:name=".newActivity"></activity>
</activity>
for calling that activity just do:
Intent intent = new Intent(MainActivity.this, newActivity.class);
startActivity(intent);
befre ask question here try some googling. and you must have to check this: Building Your First Android App and Starting Another Activity
Start new Activity like this:
Intent intent = new Intent(YourCurrentActivity.this, TargetActivity.class);
startActivity(intent);
Related
I recently have added a layout and a java file connecting it to my java code file which is taking and giving actual output by implementing an algorithm but the second layout when opened in my phone it does not react to any of the two buttons clicked on it.
Seems like an error in AndroidManifest file.
here is Manifest file code,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplicationgeneric">
<application
android:allowBackup="true"
android:label="#string/app_name2"
android:icon="#mipmap/jug_black_trasnparent"
android:roundIcon="#mipmap/jug_black_trasnparent"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Next"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".connectorclass">
<intent-filter>
<action android:name="android.intent.action.ANSWER"/>
<category android:name="android.intent.category.Calculator"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
here connectorclass.java is linked to the Layout not Responding named something xyz..
Just remove the intent filter for "connectorclass".
In AndroidManifest.xml file, you provide two intent files. That doesn't need it. Always try to add one intent-filter on your activity and this activity is your lancer activity. So remove the second intent-filter from connectorclass activity.
Then add below code on your button onClickListener
Intent intent = new Intent(MainActivity.class, connectorclass.class);
startActivity(intent);
you can remove
<intent-filter>
<action android:name="android.intent.action.ANSWER"/>
<category android:name="android.intent.category.Calculator"/>
</intent-filter>
in android manifest and can start activity using class name by default
like this
Intent intent = new Intent(this, connectorclass.class);
startActivity(intent);
try this
I want to enable bluetooth with the following code from an intent service:
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
getApplicationContext().startActivity(enableBtIntent);
The logic around my application is:
Activity A launch Activity B which launch this ENABLE_REQUEST.
I tried to launch this request from a service and after even within Activity B itself, but Activity B is always destroy and Activity A comes foreground.
Here's the manifest.
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ClassifierActivity"
android:screenOrientation="portrait"
/>
<service
android:name=".audio.SpeechRecognitionService"
android:exported="false"
android:description = "#string/speech_recognition_service_description"
/>
<service
android:name=".interaction.SmartObjectInteractionService"
android:exported="false"
/>
I couldn't find any solution!
P.S. Activity B has a Camera Fragment.
try using startActivityForResult instead of startActivity
I have two applications, the first one send an implicit intent to view a link and the second one named "MyBrowser" receives it. But when I install both apps on my phone (API level 23), the app chooser only display the Internet (default application for web viewing). If I use the AVD (API level 25), app chooser includes also "MyBrowser". Here is my first application's function:
private void startImplicitActivation() {
Log.i(TAG, "Entered startImplicitActivation()");
// Create a base intent for viewing a URL
Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
// Create a chooser intent, for choosing which Activity
// will carry out the baseIntent
Intent chooserIntent = Intent.createChooser(baseIntent, CHOOSER_TEXT);
// Verify the intent will resolve to at least one activity
if (baseIntent.resolveActivity(getPackageManager()) != null) {
Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
// Start the chooser Activity, using the chooser intent
startActivity(chooserIntent);
}
And "MyBrowser" Manifest.xml:
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyBrowserActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
</intent-filter>
</activity>
</application>
I am newbie in android and can't understand why. Please explain to me. Thank you.
I want to open activity via broadcast receiver , i tried any ways , but i am getting ActivityNotFoundException , my activity is working on normal mode, but when i want to open it from BroadCastRecevier it cause ActivityNotFoundException error,
It is my manifest ,
<activity
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:name="com.alexis.abc.ui.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And it is my broadcast receiver ,
Intent intent2 = new Intent(context, MainActivity.class);
intent2.addCategory("android.intent.category.LAUNCHER");
intent2.setAction("android.intent.action.MAIN");
context.startActivity(intent2);
Here is steps :
1 - I opening application and hiding launcher icon via following code
PackageManager packageManager = getContext().getPackageManager();
ComponentName componentName = new ComponentName(getContext(), MainActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
2 - I exiting to application and dialing a number (To triggering broadcast event) and i getting following exception
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.alexis.abc/com.alexis.abc.ui.MainActivity}; have you declared this activity in your AndroidManifest.xml?
Do you have a permission like this:
<receiver
android:name="Your receiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="action"/>
<category android:name="category" />
</intent-filter>
</receiver>
inside your Android Manifest file? If not, then try to open your Android Manifest file and put something like what I've posted above.
Or try .sendBroadcast() instead of .startActivity() on the last line of your code:
Intent intent2 = new Intent(context, MainActivity.class);
intent2.addCategory("android.intent.category.LAUNCHER");
intent2.setAction("android.intent.action.MAIN");
context.sendBroadcast(intent2);
Change your code which you want to open the application and hide the launcher icon:
ComponentName componentName = new ComponentName(getContext(), YourReceiver.class);
Don't forget to declare your BroadcastReceiver in manifest:
<receiver
android:name="YourReceiver" >
<intent-filter>
<!-- your intent filter goes here -->
</intent-filter>
</receiver>
I'm beginning to learn Android and have been reading the "Beginning Android 4 Application Development." (As well as downloading the relevant source code)..
However; I have been trying to create a very simple slideshow with a button labelled "Gallery" which will take me to a new Activity that will show a grid like layout for my photos. However, my application does not do this. When the button is pressed it either crashes the app or refuses to do anything at all.
Manifest
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="Viwer"
android:name=".Viwer" >
<intent-filter >
<action android:name="com.example.viwer.Gallery" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Any help would be greatly appreciated, I assume it's something simple but after looking at it for three hours I can't see what it is.
You need to add the Gallery activity to the Android Manifest
<activity
android:name=".Gallery"
android:label="Gallery"></activity>
In your manifest you register viewer activity in an intent-filter yet is not declare as a broadcast receiver.
Second event if it was a broadcast receiver it will never launch as you do not send any broadcast by calling startActivity
i think that what your trying to achieve is this:
Please try this:
ebutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,Viwer.calss )
startActivity(intent);
}
});