I have created an *.aar File from a Android Studio project. This file I have successfully imported to an another Android Studio project file. Now I want start the activity from the included libraries. But i am hanging and I try hour to hour...
In wich file I have to include the statement like this?
public void button_to_start_the_activity(View view)
{
Intent intent = new Intent(StartActivity.this, MainActivity.class);
startActivity(intent);
}
Should I implement this in the modul java file or in the application java file?
(Please check this out, I have not found a activity java file in my module :-/ glglgl)
Steps bevor, i have created a new activity in my main-project and i was able to start the activity without trouble.
Okay... Next question:
In the Main Manifest,...what to hell I shout declare in android:name"....?...." like this:
<activity
android:name="....??????...."
android:label="DLC"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.NoActionBar">
</activity>
Maybe, or for sure, simple question... But i try to learn a little bit AS since a week... For your understanding, i will try to explain my project with simple words....:
Try to merge two app projects in one app!
I have created a app, then i have created an another app. Now i want to merge. Simple startpage (allready exist) with the function to call the both activitys... :-/
My final solution to start a modul activity in the main app (For poeple with less experience like me)
Create in Android Studio a modul from the existing app
Open Main-Project an insert the new modul (File-->New-->Import Modul)
Right click on project folder. Search App (left side), then dependencies (right side) --> Add new from modul --> Add your modul
Check your build.cradle (Main-App) for compile project(':yourmodul')
Add this in your activity (from the Main-App)
public class StartActivity extends AppCompatActivity {
public void gotocalc(View view)
{
Intent intent = new Intent(StartActivity.this, YourModulClass.class);
startActivity(intent);
}
gotocalc is for start with a button android:onClick="gotocalc" set in your layout.xml in the Main App.
Clean, Rebuild
Related
I have published my app now and found that it is creating two shortcut icons where as when I install through android studio it creates only one shortcut. I have added duplicate false and sharedpreference has also been used to check once icon is created. Why the app behaving different and how can I fix it now? This is my code for creating shortcut.
public void createShortCut() {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(StartupActivity.this).edit();
editor.putBoolean("shortcut", true).apply();
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Smart App");
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), SplashScreen.class));
sendBroadcast(shortcutintent);
}
and before calling above method I have below code which runs on activity start.
if (!sharedPreferences.getBoolean("shortcut", false)) {
createShortCut();
}
When you install from Android Studio (directly from an .apk), no shortcut is made. However, apps installed from the Google Play Store will automatically sometimes create a shortcut after installation.
So when a user installs your app from the play store, two shortcuts are made, one from your app and one from the installation.
EDIT: This solution might prove useful to you: How to detect shortcut in Home screen
I read almost every answer obout this topi c but i cannot find a working solution for my case or maybe I'm missing somthing.
I use eclipse as IDE and I would like to use an external library for example I'm trying to add this Library to my project but I don't understand what i'm doing wrong.
I tried download the full project and import it into the workspace, mark it as library and then under my project and add it as reference.
If everything is ok how should I call an activity from the linke library?
I tried to defind the linked activity into my manifest file but without success.
Could you please point me in the right way?
Thank you
You need to write code which will call the library activity inside onCreate() or any other method which you choose like
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
//Here you need to call directory chooser activity.
final Intent chooserIntent = new Intent(this, DirectoryChooserActivity.class);
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
.newDirectoryName("DirChooserSample")
.allowReadOnlyDirectory(true)
.allowNewDirectoryNameModification(true)
.build();
chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config);
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);
}
Import DirectoryChooserActivity and DirectoryChooserConfig class in your activity; If you are not able to import the mentioned class then you are not added library into the project correctly.
I am new in android development and coding java and xml.
but I was following this tutorial:
http://www.steventrigg.com/activities-and-the-action-bar-create-an-alarm-clock-in-android-tutorial-part-1/#comment-296
then I had this error when using Intent. The word "Intent" under switch became red and there is an error "cannot find symbol class Intent"
Can someone explain to me what is going on and how to solve this?
This is the last part of my code under AlarmListActivity.java
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
switch (item.getItemId()) {
case R.id.action_add_new_alarm: {
Intent intent = new Intent(this,
AlarmDetailsActivity.class);
startActivity(intent);
break;
}
}
return super.onOptionsItemSelected(item);
}
Look at your AlarmListActivity again and check the import statements at the top and make sure it includes the line:
import android.content.Intent;
If you intend to use any pre-existing classes that aren't part of the java.lang package, you generally have to import those classes. An Android Intent, for example, is a pre-built class, written by the Android development team, that allows for notification of other apps/activities. If you want to use Intent, you'd then have to import the package containing Intent.
When you write new Intent(), the compiler sees that you're requesting the construction of a new object, but because that object is not found in the java.lang package, it needs to know where to look for a blueprint to build that object. The import statement is the location of that blueprint.
I took a look at the tutorial and in the manner of experienced programmers, the author seems to have glossed over a few basic, but nonetheless, important things, such as the import statements that make his sample code work.
I had a same problem which I just resolved, by understanding how Android Studio indexes files, As you know Building an Android App is quite complicated process. So Android studio has some internal references which it keeps getting updated on change of every file that you have created.
I arrived at this post while searching for the solution,
This is how I got this problem
I usually wont create an activity under the main project package, I create sub packages to organize files as per the design pattern that I use, for eg If my APP name is com.example.testingaravind then inside that I usually create packages such as activites, services, models, managers etc ... So today I just created an activity first and then moved that activity into activites package via Android Studio, I started facing the same issue what you have described, Below was my source code
public class BootstrapActivity extends ActionBarActivity {
private static final String TAG = "BootstrapActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bootstrap);
}
public void startServiceOnClickHandler(View view) {
Intent intent = new Intent(BootstrapActivity.this , AnalyzerService.class);
startService(intent);
}
}
In the method startServiceOnClickHandler it was showing an error saying,
"Cannot resolve constructor Intent" I searched a lot in google and found that
When I move a file from one package to other package, my manifest file wont get updated, in the manifest we mention the activity name and its package path in my case it should be
android:name=".activities.BootstrapActivity"
But it was
android:name=".BootstrapActivity"
Because of this, Android studio was unaware that a class called BootstrapActivity exists inside the activities folder,
This seems to be a bug in the way how android studio works. Android Studio has to update manifestfile when I move the activity class file from one package to another package.
I am posting this to help others who might arrive at this post with the similar usecase.
Check name in manifest file in activity tag specify correct package for example your
<activity
android:name="Your-Package.MainActivity"
android:exported="true" />
In second case If you are using kotlin class inside java class, after configuring kotlin in project can solve the project...
Mixare has an application (Open source) that lets you view POIs with your camera. It gives you the possibility to call the app from your application thanks to this :
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("http://ws.geonames.org/findNearbyWikipediaJSON"), "application/mixare-json");
startActivity(i);
The problem is that user must have the app installed in addition to my app, so what I did is that I imported the whole app within mine, with all its resources and stuff.
But I don't know how to call the main activity MainActivity.java, which resides in the package org.mixare.
How can I make an intent to call this activity ? And how do I declare it in the manifest ?
If you have added the code and resources of the app to your own app, then you should declare and call it's activities as they were your own.
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
This being said, it's not a trivial task. You need to merge AndroidManifest and could get into trouble if you don't know what you're doing. For instance, user can have the Mixare app in addition to yours and intent could have same actions etc.
There is an alternative to this. You could check if Mixare app is installed and if not ask user to do so. This could be more "android way of doing things", depending on your use case.
Look at,
http://code.google.com/p/mixare/wiki/DisplayYourOwnData for how to start mixare via Intent.
Alternatively, you can use mixare as your library project and then call its MainActivity class directly from your application as Using an Android library project Activity within another project.
Quoting the same here -
Declaring library components in the manifest file
In the manifest file of the application project, you must add
declarations of all components that the application will use that are
imported from a library project. For example, you must declare any
, , , , and so on, as well as
, , and similar elements.
Declarations should reference the library components by their
fully-qualified package names, where appropriate.
Then you can definitely call,
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
No, it is very hard to do a 2+2=4 kind of addition of manifest files etc.
I see there are two ways to handle this:
Use the external app: Check if the user has external app you want him to have. Else, direct him to the right link. You can get the package name of the publiched app and use it in this function:
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed ;
}
Combining code: This has no direct/correct answer. You need to study the code and integrate with your existing one.
//appPackageName,appClassName can be found in Logcat
ComponentName component = new ComponentName("appPackageName","appClassName");
Intent intent = new Intent();
intent.setComponent(component);
startActivity(intent);
The error show after I update my ADT, the project is created before the update.
In Login Activity,
public class LoginActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Do something here... if login success, Start another activity
Intent i = new Intent(LoginActivity.this, MainActivity.class);
LoginActivity.this.startActivity(i);
}
.......
}
In MainActivity,
public class MainActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
//......
}
}
I try to remove all the code inside and back to a blank activity. The error is not happen because of the code inside the activity. I think is abut the extend FragmentActivity
Here is the error trace:
Unable to resolve superclass of Lhk/iactive/imoodle/activity/MainActivity; (15)
Link of class 'Lhk/iactive/imoodle/activity/MainActivity;' failed
I get this error after I update my ADT.
I do some research on this topic. I try to import the android-support-v4.jar again and this do not fix the problem.
I also read some blog like THIS ONE can not help me too :(
I have solve the problem by myself. I am going to share the solution hope there is other people who suffer from the same error can save some time :D
I try many method for example go to build Path Config -> Order and Exprot, All the library is already checked. And the NoClassPathFound error is still showing.
I have no external Jar for the project and The error is from FragmentActivity from Android Support Library.
Then I delete the android-support-v4.jar complete and add it again by right clicked the project -> Android Tools -> Add support library...
After the new support library added. All the error fix. :D
This worked for me:
For all projects (app and library):
Right click the project, and choose Properties
Go to Java Build Path-Order and Export.
Tick 'Android Private Libraries'