I have 2 projects, and I want to embed a project in other. I have created 2 projects and have made a project as library file and inserted in other but I am still unable to get it working. I have taken a simple activity and want to display a toast message, using Intent I have given the address of the next project library. This is the code of the main (first) project.
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.sec_pro";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "First Activity", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, com.example.sec_pro.MainActivity.class);
EditText editText = (EditText) findViewById(R.id.editText1);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.integrate.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:name="com.example.sec_pro.MainActivity" >
</activity>
</application>
Now this "sec_pro" is the library file of my next project which I have inserted in the first project.
Please help.
Thanks in advance.
I think you have missed to declare your library activity in Manifest.
try this code to declare in to manifest under application tag:
<activity android:name="PackageName.YourLibraryActivity" />
Please check onClick method again, I think you missed a statement:
startActivity(intent);
Related
Hi I'm following Google documentation to open a dummy App with the Start command but is not working for me.
I created a new default project using Android Studio wizard with a mobile and a wear module.
I didn't touch anything but 'android:label' of Wear Module manifest to "Hola" (hello in Spanish) and when I say "Iniciar Hola" ("Start Hello") Wear makes a google search with the "hola" keyword.
Wear module or mobile module aren't being launched.
What I'm missing :'( seems pretty easy from Google docs...
PS: I'm testing over BT on a wear device
Mobile manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.basetis.wearapp" >
<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>
</application>
</manifest>
Mobile Activity
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Wear Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.basetis.wearapp" >
<uses-feature android:name="android.hardware.type.watch" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault" >
<activity
android:name=".WearActivity"
android:label="Hola" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Wear Activity
public class WearActivity extends Activity {
private TextView mTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wear);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub stub) {
mTextView = (TextView) stub.findViewById(R.id.text);
}
});
}
}
Ok... the spanish word to Start an application is "Abrir" not "Iniciar", but on wear UI the menu entry to open apps is "Iniciar" so an applause for Google UX Team :'(
It looks like the voice commands are for launching apps on your phone, not launching a wear app.
I'm able to say "Start calculator" and it opens the calculator app on my phone.
What you could do is launch an activity on the phone and then that activity launches the wear app that you intended.
I am trying go from one activity to its sub-activity (i.e, a new page with more buttons), but every time I click the button, the application "Unfortunately stops running".
I believe that the flaw lies in the manifest where I might writing something wrong under the intent-filter section.
Mind taking a look?
public class MainActivity extends ActionBarActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
addListenerOnButton2();
}
//First Activity
private void addListenerOnButton() {
// TODO Auto-generated method stub
button = (Button) findViewById(R.id.activity_one);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent IntentOne =
new Intent(arg0.getContext(), ActivityOne.class);
arg0.getContext().startActivity(IntentOne);
}
});
}
//Second Activity, will look into it later. Making it Explicit for now.
public void addListenerOnButton2() {
button = (Button)findViewById(R.id.activity_two);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View argo) {
Intent IntentTwo = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.ca"));
startActivity(IntentTwo);
}
});
}
}
///////////////////////////////////////////////////////
Here is the Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.poop"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.poop.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:name="com.example.poop.ActivityOne"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.poop.ActivityOne" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I have not added ActivityTwo yet to the manifest.
You can't have Activities that aren't registered in the Manifest. I don't see an ActivityOne registered in your AndroidManifest.xml
Sorry, I am new to android apps. creation. I have referred pretty much all solutions but this just doesn't work...and I don't see any problem in below simple-code. My app is simple, Load the splash screen, then load the webview. What is the problem below?
ERROR I get is:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wwes.EZEE/com.wwes.EZEE.SecondPage}; have you declared this activity in your Manifext.xml
[COMMENT] Pls. Look below, I have already declared it. what's wrong?
Files are:
MainActivity.java: Here I load the splashscreen image.
package com.example.EZEE;
import com.wwes.EZEE.SecondPage;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Thread for displaying the Splash Screen //
Thread splash_screen = new Thread() {
public void run() {
try {
sleep(1000);
} catch (Exception e){
e.printStackTrace();
} finally {
Intent i = new Intent(MainActivity.this, SecondPage.class);
startActivity(i);
}
}
}; splash_screen.start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
SecondPage.java: This loads the webview.
package com.wwes.EZEE;
public class SecondPage extends Activity {
WebView browserView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Removed the title bare in the Application //
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_second_page);
// Creation of the Webview found in the XML Layout file //
browserView = (WebView)findViewById(R.id.webView1);
// Enable Javascripts //
browserView.getSettings().setJavaScriptEnabled(true);
browserView.getSettings()....
browserView.getSettings()....
browserView.getSettings()....
browserView.getSettings().setLoadsImagesAutomatically(true);
// Removed both vertical and horizontal scroll bars //
browserView.setVerticalScrollBarEnabled(false);
browserView.setHorizontalScrollBarEnabled(false);
browserView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
// Webview Wrap //
browserView.loadUrl("http://www.ABCDE.com");
browserView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onBackPressed()
{ if(browserView.canGoBack())
browserView.goBack();
else super.onBackPressed(); }
}
activity_main.xml:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#800808"
android:scaleType="fitStart"
android:visibility="visible"
android:src="#drawable/logo" />
4) activity_second_page.xml:
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:visibility="gone"
android:layout_alignParentTop="true" />
5) manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wwes.EZEE"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
----------------------------------updated----------------------------------
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.wwes.EZEERACKS.MainActivity" //// UPDATED ///
android:configChanges="keyboard|keyboardHidden|orientation|smallestScreenSize"
android:screenOrientation="portrait"
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:name="com.wwes.EZEE.SecondPage"
android:label="#string/title_activity_second_page" >
</activity>
</application>
</manifest>
Thanks for the help!
you must defin your activity in manifest.xml file
<activity android:name=".SecondPage"
android:label="#string/title_activity_second_page" >
</activity>
You don't need the <intent-filter> tag in the SecondPage tag of the manifest because you are already starting the activity from MainActivity.
So, remove this:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
from this:
<activity
android:name="com.wwes.EZEE.SecondPage"
android:label="#string/title_activity_second_page" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
how come your main activity is com.example.EZEE.MainActivity while secondPage is com.wwes.EZEE.SecondPage? I would check if both resides on the same package.
I bet if you have changed the secondPage name to com.example.EZEE.SecondPage it will work.
if it didn't work I would remove the android:name of both activity and within the "", click ctrl + space and let the eclipse handle putting the naming to the activity. therefore the shown activities are guaranteed to work in the application.
Hope this works with you, please give me a feedback.
Just change your defination of .SecondPage to the following in manifest.xml file
<activity android:name="com.wwes.EZEE.SecondPage"
android:label="#string/title_activity_second_page" >
</activity>
I am programming an app. There is no errors. I can run the app, but when I press the button it says:
Unfortunately the app has stopped.
What can I do?
Here is my activity code:
Button button1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 =(Button)findViewById(R.id.button1);
button1.setOnClickListener(this);
}
private void button1Click()
{
startActivity (new Intent ("com.example.cp3.tutorial.Class2"));
}
public void onClick(View v) {
switch (v.getId())
{
case R.id.button1:
button1Click();
}
}
and the manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.cp3.tutorial.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:name="com.example.cp3.tutorial.Class2"
android:label="#string/title_activity_class2" >
</activity>
</application>
</manifest>
Change button1Click() like this:
private void button1Click()
{
startActivity (new Intent (MainActivity.this, Class2.class));
}
startActivity (new Intent ("com.example.cp3.tutorial.Class2"));
here in your code! you refer to a package to be opend. if you want to open an activity on button click use this code:
Intent intent = new Intent(firstActivity.this, secoundActivity.class);
startActivity(intent);
put this on your click listener, instead of firstActivity put your current activity and secoundActivity put your activity name you want to be opened.
Hope this help you.
I've been at this for hours and can't figure it out. When I debug, it gives the above error. I'm new to this so go gentle if it's something obvious that I"m missing...
here's the code which introduced the crash from the first activity, it's still labeled 'Main':
//-- Menu Press --
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//-- Handle item selection
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent menu = new Intent(this, Menu.class);
menu.putExtra("plWin", plWin);
menu.putExtra("plLoss", plLoss);
menu.putExtra("plDraw", plDraw);
startActivity(menu);
return true;
case R.id.menu_reset:
if (opCounter > plCounter) {
plLoss++;
}else if (opCounter < plCounter) {
plWin++;
}else {
plDraw++;
}
opCounter = 0;
plCounter = 0;
return true;
default:
return false;
}
}
and the second activity, currently named 'Menu':
public class Menu extends Activity {
Intent menu = getIntent();
int wins = menu.getIntExtra("plWin", 0);
int losses = menu.getIntExtra("plLoss", 0);
int draws = menu.getIntExtra("plDraw", 0);
private TextView winNum = null;
private TextView lossNum = null;
private TextView drawNum = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//-- Win Counter --
LinearLayout winView = (LinearLayout) findViewById(R.id.plLeft);
winNum = (TextView) winView.findViewById(R.id.winNum);
winNum.setText("" + wins);
//-- loss Counter --
LinearLayout lossView = (LinearLayout) findViewById(R.id.plMid);
lossNum = (TextView) lossView.findViewById(R.id.lossNum);
lossNum.setText("" + losses);
//-- Draw Counter --
LinearLayout drawView = (LinearLayout) findViewById(R.id.plRight);
drawNum = (TextView) drawView.findViewById(R.id.drawNum);
drawNum.setText("" + draws);
}
public void onBackPressed() {
finish();
super.onBackPressed();
}
}
and here's my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sesto.life.counter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Main"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sesto.life.counter.Menu"
android:label="#string/title_activity_menu" >
</activity>
</application>
I'm looking for ideas. Thank you all in advance
I only see one possible mistake is at Intent menu = new Intent(this, Menu.class);
. Please check Menu.class is your Menu class but not Android Menu View (located at android.view.Menu). The logcat told that it can not find android.view.Menu in manifest. Hover your mouse pointer above Menu.class to check which class you imported for this.
Change
<activity
android:name="com.sesto.life.counter.Menu"
android:label="#string/title_activity_menu" >
</activity>
to
<activity
android:name=".Menu"
android:label="#string/title_activity_menu" >
</activity>
and see if that helps
I got this error message when I forgot to add The Activity in Manifest file.