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>
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 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);
I would like to make my webapp look as similar as I can to a native app, now I just realized that there's no notification bar at the top and that Android back button doesn't take you to the last screen but closes the app. Does anybody know how to fix this?
Manifest
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true">
<activity
android:name="com.example.mywebapp.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String URL = "file:///android_asset/Compatibilidades/public_html/index.html";
WebView myWebView = (WebView) this.findViewById(R.id.webView);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
myWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
myWebView.loadUrl(URL);
}
#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;
}
}
class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Found the solution, you need to put this parameter in the activity in AndroidManifest.xml
<activity
android:theme="#android:style/Theme.NoTitleBar">
In order to support the back button, you can do the following (source):
public class MainActivity extends Activity {
#Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
I want to move from one activity to another (using virtual device). When I click on button to move, My emulator ones a dialog box showing unfortunately SMS1 has stopped working (SMS1 is my app name).
Can anybody help me in correcting my code?
MainActivity.java:
package com.example.sms1;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener
{
Button b1;
TextView tv1;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button1);
tv1 = (TextView) findViewById(R.id.textView1);
b1.setOnClickListener(this);
}
#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 onClick(View v)
{
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),NextActivity.class);
startActivity(i);
setContentView(R.layout.avtivity_next);
}
}
Here is the NextActivity
package com.example.sms1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class NextActivity extends Activity {
TextView tv1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.avtivity_next);
tv1 = (TextView) findViewById(R.id.textView1);
}
#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.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sms1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.sms1.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>
NextActivityLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".NextActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next activity" />
</RelativeLayout>
MainActivity Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="80dp"
android:layout_toRightOf="#+id/textView1"
android:text="Button" />
</RelativeLayout>
First You have to use this code in MainActivity.java class
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),NextActivity.class);
startActivity(i);
}
You can pass intent this way.
Second
add proper entry into manifest.xml file.
<activity android:name=".NextActivity" />
Now see what happens.
You haven't defined NextActivity in the AndroidManifest.xml file.
Add these lines in android manifest after</activity> tag. It should work.
<activity
android:name=".NextActivity" >
</activity>
final code will be
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="Main Activity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NextActivity" >
</activity>
</application>
button1 in activity2
code written in activity 2
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
// starting background task to update product
Intent fp=new Intent(getApplicationContext(),activity1.class);
startActivity(fp);
}
});
This might help
Simply add your NextActivity in the Manifest.XML file
<activity
android:name="com.example.sms1.NextActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
public void onClick(View v)
{
startActivity(new Intent(getApplicationContext(), Next.class));
}
it is direct way to move second activity and there is no need for call intent
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent = new Intent(Activity1.this,Activity2.class);
startActivity(intent);
}
1) place setContentView(R.layout.avtivity_next); to the next-activity's onCreate() method just like this (main) activity's onCreate()
2) if you have not defined the next-activity in your-apps manifest file then do this also, like:
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="Main Activity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NextActivity"
android:label="Next Activity" >
</activity>
</application>
You must have to perform the 2nd step every time you create a new activity, otherwise your app will crash
When you have to go from one page to another page in android changes made in 2 files
Intent intentSignUP = new Intent(this,SignUpActivity.class);
startActivity(intentSignUP);
add activity in androidManifest file also like
<activity android:name=".SignUpActivity"></activity>
setContentView(R.layout.avtivity_next);
I think this line of code should be moved to the next activity...
Below code is working fine with Android 4.3:
Intent i = new Intent(this,MainActivity2.class);
startActivity(i);
First you have to declare the activity in Manifest. It is important. You can add this inside application like this.
It is mainly due to unregistered activity in manifest file as "NextActivity"
Firstly register NextActivity in Manifest like
<activity android:name=".NextActivity">
then use the code in the where you want
Intent intent=new Intent(MainActivity.this,NextActivity.class);
startActivity(intent);
where you have to call the NextActivity..
Register your java class on Android manifest file
After that write this code on button click
startActivity(new intent(MainActivity.this,NextActivity.class));
You can do
Intent i = new Intent(classname.this , targetclass.class);
startActivity(i);
I have set the layout Test into my app
<activity
android:name="com.example.test.TestActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When I run it it's not take the testactivity. I have run (Run as app) many time. it's take MainActivity. Do someone know how to modified it.
if this is need to somewhere please tell me. What I want is now change the app to run the Testactivity instead of MainActivity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".TestActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="36dp"
android:layout_marginTop="152dp" android:onClick="btnTest"
android:text="Button" />
</RelativeLayout>
Activity:
public class TestActivity extends Activity {
#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.main, menu);
return true;
}
public ArrayList<String> GetArray(String input){
ArrayList<String> arr= new ArrayList<String>();
return arr;
}
public void btnTest(View view){
Toast.makeText(getApplicationContext(), "This is test", Toast.LENGTH_SHORT);
}
}
Inside the overridden onCreate() ,Mention your test_activity xml file instead of main Activity.xml file.
setContentView(R.layout.test_activity);
your problem is that you have setted the same layout for both of your activities .
in your Activity TestActivity , in the onCreate() method ;you should set the content view like this :
setContentView(R.layout.test_activity);
instead of :
setContentView(R.layout.activity_main);
If you just want to change the content XML file just change the
setContentView(R.layout.test_activity);
in the onCreate() method.
If you want 2 activites then you need to add this
<activity
android:name="com.example.test.TestActivity"
android:label="#string/app_name" >
</activity>
to your manifest and a new java class to run the activity and change to the new activity with an intent.
Intent i = new Intent(activity_main.this, TestActivity.class);
startActivity(i);
Try this...
Eclipse => Project-> Clean
change the content view in onCreate() just change the
setContentView(R.layout.test);
And change it in your Manifest file:
<activity
android:name=".TestActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>