Start activity from another package - Issue - java

I downloaded library project from github and imported it into my app project.The problem is that i want to start activity from this library in my main app class.I tried many ways and one of them was:
Intent intent = new Intent();
intent.setComponent(new ComponentName(
"com.tehedligmail.restorancafeler.RestaurantActivity
,
"com.cunoraz.pickImages.MainActivity"));"
startActivity(intent);
This is my log:
08-29 04:40:13.937: E/AndroidRuntime(11778):
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tehedligmail.restorancafeler.RestaurantActivity/com.cunoraz.pickImages.MainActivity};
have you declared this activity in your AndroidManifest.xml?
_---------------------------------------------------------------------------
i tried this but manifest can't show the package and activity class:
<activity android:name="com.luminous.pick.MainActivity">
<intent-filter>
<action android:name="com.luminous.pick.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
As i understand from log i should define the class that i want to launch in my manifest,but i couldn't write this,even autocomplete of manifest didn't show this class's name.
Thanks in advance.
For more information This is image shows library and main project of my app

As the document, I think the package name is problem. Can you try this?
intent.setComponent(new ComponentName( "com.cunoraz.pickImages", "com.cunoraz.pickImages.MainActivity"));"
And no need to declare this activity in AndroidManifest.xml

Related

How to connect two activities to make a program?

I am a beginner in java.
I want to make sure to link my second main activity on my first activity.
I try to put a line of code in my first activity but that does not connect anything at all.
I put the line of code:
Intent intent = new Intent(this, DeuxiemeActivity.class);
startActivity(intent);
finish();
Thanks,
Inside AndroidManifest.xml,
Change
<activity android:name=".MainActivity">
to this,
<activity android:name=".MainActivity" android:noHistory="true">
noHistory="true" and finish() both are similar.
But, When we start a new activity, It will be closed at the same time. So using noHistory="true" is better than using finish();.

Launch a new screen (activity) instead of replacing the crurent one

My first App
This is my first android app - QR Code Scanner using ZXingScanner Library.
Is there any way to launch a new screen (activity) instead of replacing the crurent one, so i can press back from the scanner to go back to main screen where is the button?
Please help me. Thanks all
I think that this site can help you: http://developer.android.com/training/basics/firstapp/starting-activity.html
In short words:
You need to create new
Intent myIntent = new Intent(this, SecondActivity.class) and than start it by startActivity(myIntent).
Additionally it will be good to define your MAIN activity in AndroidManifest.
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You should create 2 activities in your app.
From first activity send an intent to the second activity that you created before (I think that you can create one). With sending an intent to another activity the first one remain, and you can use back button to load that.
Now this is the easiest way that you can send an intent:
Intent intent= new Intent(Activity1.this,Activity2.class);
startActivity(intent);
But there is some other ways to send an activity(similar to this one):
How to start new activity on button click

Unable to find explicit activity class Android

Ugh, so many posts on StackOverflow similar to my problem but none fix it :/
I am currently learning android development. In my main activity I do:
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.changeName:
Intent intent = new Intent(this, PreferenceActivity.class);
startActivityForResult(intent, 1);
return true;
}
return false;
}
Preference.java is a freshly created activity with nothing in it except the automatically created onCreate method. The error is:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.package.chat.oneway.client/android.preference.PreferenceActivity}; have you declared this activity in your AndroidManifest.xml?
My android manifest has:
<application
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".ChatClient"
android:label="#string/app_name" />
<activity android:name=".Parent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PreferenceActivity"></activity>
</application>
As you can see, .PreferenceActivity is in the manifest. The packages for the ChatClient and PreferenceActivity activities are the same com.package.chat.oneway.client package.It's been driving me nuts for the past 4 hours.
As you can see, .PreferenceActivity is in the manifest.
Yes, it is. However, that is not what your Intent is using. If you look more closely at the error message, you will see that your Intent is using android.preference.PreferenceActivity.
This comes when you reuse existing class names. There are countless possible class names. Rename yours to something else, and you can avoid this sort of problem in the future.
Or, if you are completely set on having your class named PreferenceActivity, then remove the import android.preference.PreferenceActivity statement from the class where you are creating your Intent. Or, change your Intent to:
Intent intent = new Intent(this, com.package.chat.oneway.client.PreferenceActivity.class);

Is it possible to call the mainActivity class of another project ?

I have 3 android projects, which they have different functions. Each project has its own mainActivity class.
Now I want to merge the 3 projects into one. I can think of 2 ways to do it.
First way: open one of the 3 projects, then create new java class and xml files and copy all java class and xml content from other 2 projects. However, each project has its own mainActivity class. I don't know whether I should preserve one mainActivity class only and rename other 2 mainActivity class of other 2 projects. It seems that it is easy to encounter lots of bugs and messy.
Second way: use 3 buttons. onclick first button then the mainActivity class of project 1 will run. onclick second button then the mainActivity class of project 2 will run. onclick third button then the mainActivity class of project 3 will run. However, I don't know whether it is possible to do so. If yes, How can I do so ? I know how to onclick on a button to go to a new activity but is that the same to apply to onclick going to other project's mainActivity ?
I prefer the second method, if it is possible to do so. Could anyone help ? Please advise , thanks.
This think it's impossible, you need to import all functions in 1 project...
You can't open other project with one button, you need to import classes and activities in your global project that you needs or create a new classes, but you can't call other projects. Good luck!
If you add a custom action to your activity:
<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>
<intent-filter>
<action android:name="com.example.action.MYACTION" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
You can invoke it via implicit intent as long as the app already installed on the device:
Intent i = new Intent("com.example.action.MYACTION");
startActivity(i);

Android, bring already started activity back to front

My android application has multiple activities. Each activity has a 'Back to Home' button. For example, Main activity opens sub-activity A, sub-activity A opens sub-activity B.
On the screen of sub-activity B, there's a 'Back to Home' button which is supposed to bring back the Main activity into visibility.
I've tried the flag Intent.FLAG_ACTIVITY_REORDER_TO_FRONT but no use.
This is a part of my AndroidManifest.xml:
...
<activity android:name="vn.agritrade.Main_Activity"
android:label="Agritrade"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:uiOptions="splitActionBarWhenNarrow"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
...
This is how I relaunch the Main activity:
/**
* Relaunch main activity (called by 'Back to Home' button)
*/
public void open_main_activity(View view) {
Intent intent = new Intent(this,Main_Activity.class);
intent.putExtra(DEFAULT_EXTRA,"");
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
What else should I need?
Use below code it may help,
Intent intentHome = new Intent(getApplicationContext(), MainActivity.class);
intentHome.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentHome.putExtra(DEFAULT_EXTRA,"");
startActivity(intentHome);
It is worked for me.
Don't forget to mark as answer it is help to you.
Intent.FLAG_ACTIVITY_CLEAR_TOP may solve your problem
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP
Intent intent = new Intent(this,Main_Activity.class);
intent.putExtra(DEFAULT_EXTRA,"");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
My final solution is:
Keep the main activity stay open
Each time I need to turn back to main screen: close all sub-activities

Categories

Resources