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

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

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();.

Android Manifest Confusion

I noticed that there are two ways to start an Activity with Intent.
1) Using - [android:name=".MainActivity"]
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
2) Using - [action android:name="com.example.MainActivity"] from the Intent_Filter
String actionName = "com.example.MainActivity";
Intent intent = new Intent();
intent.setAction(CUSTOM_ACTION);
context.startActivity(i);
So what's the difference? Why do we have to set both the name and the intent_filter in the manifest if they both do the same thing?
===---==
Second confusion I have is... Is there a way to use the "OK Google" voice-launch option to launch an Activity that's NOT shown in the app list? Basically actual App Launcher launches the "default homepage" of the app, whereas voice launch takes you to a specific Activity directly?
I suspect some combo of these might get it done:
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
If your class is in your main package, you can use this way:
.YourClass
or
com.example.YourClass
If your class isn't in your main package, you should use this way:
packagename.YourClass

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

How can I get a number placed in a text message on Android?

I want to add a feature to my app that when I touch the number in a message, the user can decide to send the number to my app or Android Dialer.
For example my friend send me a code and i want to use this code for special ussd code that my app run it.
I think I have to use implicit intent but I don't know how?
Thanks
I have quoted the below links
-intent filter
-Intents implicit\explicit
Implicit intents specify the action which should be performed and
optionally data which provides data for the action.
For example the following tells the Android system to view a webpage.
All installed web browsers should be registered to the corresponding
intent data via an intent filter.
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.vogella.com")); startActivity(i);
If an Explicit intent is send to the Android system, it searches for all
components which are registered for the specific action and the
fitting data type.
If only one component is found, Android starts this component
directly. If several components are identifier by the Android system,
the user will get an selection dialog and can decide which component
should be used for the intent.
How to use
You can register your own components via Intent filters. If a
component does not define one, it can only be called by explicit
intent.
Register an activity as Browser
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
UPDATES
A code sample for mimeType
<activity android:name="ShareActivity">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="image/*"/>
</intent-filter>
I assume you are talking about a number in a SMS that you received. On clicking that number you want the user to get an option to either dial or use your app.
If yes then you need to include intent filter in your manifest file for launcher activity.

Launching Intent cannot find Activity

My program has a list of tabs that each contain a list of people. Clicking a person should edit their details, but instead, clicking a person throws an ActivityNotFoundException. My code that starts the edit activity:
Intent intent = new Intent("my.package.EDIT"); // Person is both
intent.putExtra("my.package.PERSON", (Parcelable) myPerson); // Parcelable and
GroupArrayAdapter.this.getContext().startActivity(intent); // Serializable
Relevant part of AndroidManifest.xml:
<activity android:name="EditActivity">
<intent-filter>
<action android:name="my.package.EDIT" />
</intent-filter>
</activity>
What's going on?
There's two ways to start an Activity, either explicitly or implicitly. Explicitly means that you use the class name directly; usually if you're calling an Activity that is within your own application, what you mean to use is the explicit method because it's far easier:
Intent intent = new Intent(context, EditActivity.class);
context.startActivity(intent);
However, if you really do mean to use implicit filtering, then your intent filter is missing something. Every implicit intent filter requires the category android.intent.category.DEFAULT (with few exceptions). Try this and see if it works:
<activity android:name="EditActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="my.package.EDIT" />
</intent-filter>
</activity>
Suggested reading: intent filters.
When you instantiate your Adapter, pass the context from the calling activity. Then in your adapter use context.startActivity(...);

Categories

Resources