Android從一個APP跳轉到另一個APP的主介面或某頁面,並傳遞資料
1. Android 從一個 APP 跳轉到另一個 APP 主介面
Intent intent = new Intent(Intent.ACTION_MAIN);
//前提:知道要跳轉應用的包名、類名
ComponentName componentName = new ComponentName("com.example.hust_twj.secondapp", "com.example.hust_twj.secondapp.MainActivity");
intent.setComponent(componentName);
startActivity(intent);
本 Demo 包括 2 個測試的 APP ,FirstApp 主介面有 2 個按鈕,分別進入 SecondApp 的主介面和某指定的介面;而SecondApp 主介面僅有一個登陸的按鈕,點選該按鈕可以進入登陸介面。
從 FirstApp 進入 SecondApp 的主介面跳轉截圖(程式碼如上):
2. Android 從一個 APP 跳轉到另一個 APP 的某 activity
(1) 把要跳轉的目標 APP 的指定 activity 暴露出來
在 AnroidManifest 檔案中給 activity 節點設定 Android:exported="true"
,該屬性表示當前 activity 能否被另外一個Application 的元件啟動,true
false
不允許。預設是false
。注意:該屬性是四大元件都擁有的。
<activity
android:name=".LoginActivity"
android:exported="true">
</activity>
(2) 啟動/跳轉
Intent intent = new Intent();
intent.setClassName("com.example.hust_twj.secondapp", "com.example.hust_twj.secondapp.LoginActivity" );
startActivity(intent);
第一個引數是目標 APP 的包名,第二個引數是目標 APP 的 activity 的全稱。如果目標 APP 的 activity 沒有暴露入口,則會報許可權禁止錯誤。
從 FirstApp 進入SecondApp 的某指定介面(登陸介面):
3. 跳轉時使用 Bundle 傳遞資料
在 FirstApp 中使用 Bundle 傳遞資料:
public void go2Main(View view){
ComponentName componentName = new ComponentName("com.example.hust_twj.secondapp","com.example.hust_twj.secondapp.MainActivity");
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("FIRST_APP_KEY", "你好 ,MainActivity");
intent.putExtras(bundle);
intent.setComponent(componentName);
startActivity(intent);
}
public void go2Login(View view){
Intent intent = new Intent();
intent.setClassName("com.example.hust_twj.secondapp", "com.example.hust_twj.secondapp.LoginActivity");
Bundle bundle = new Bundle();
bundle.putString("FIRST_APP_KEY", "你好 ,LoginActivity");
intent.putExtras(bundle);
startActivity(intent);
}
在 SecondApp 中,假如 MainActivity 和 LoginActivity 都有 TextView 用於顯示從 FirstApp 中傳過來的資料(本 Demo 中沒有 TextView ),那麼在 MainActivity 和 LoginActivity 中接收資料如下:
TextView mTextView = (TextView) findViewById(R.id.tv_main);
Bundle bundle = this.getIntent().getExtras();
if (bundle != null){ //防止直接啟動MainActivity時空指標閃退
String value = bundle.getString("FIRST_APP_KEY");
mTextView.setText(value);
}
至此, APP 間的跳轉及傳遞資料就結束啦~
相關推薦
Android從一個APP跳轉到另一個APP的主介面或某頁面,並傳遞資料
1. Android 從一個 APP 跳轉到另一個 APP 主介面 Intent intent = new Intent(Intent.ACTION_MAIN); //前提:知道要跳轉應用的包名、類名 Comp
android 使用startActivity()從一個fragment 跳轉另一個activity出錯
系統沒有崩潰,run裡也沒有明顯的錯誤,但是event Log裡提示跳轉失敗: 20:14:44 error: cannot connect to daemon 20:14:44 'E:\sdk\platform-tools\adb.exe,start-server' failed --
android fragment跳轉另一個activity出錯
最近遇到了一個麻煩,就是我用fragment為模板寫了一個小的程式,其中包括在fragment中點選跳轉到另一個activity中,但是當我建立一個activity時,程式就炸了。 這個錯誤一直困擾了我幾天,各種百度都沒有找出原因,最後我從最基礎的fragment模板開始,建activity測試
android從一個activity跳到另一個activity 報錯 經驗總結
首先------上程式碼 setting=(ImageButton)findViewById(R.id.setting); setting.setOnClickListener(new View.OnClickListener() { @Overrid
springmvc怎麽重定向,從一個controller跳到另一個controller
save exce exception pac pro 方式 con .net 它的 第一種情況,不帶參數跳轉: 方法一:使用ModelAndView return new ModelAndView("redirect:/toList"); 這樣可以重
微信小程序中跳轉另一個小程序
微信 open mini ucc ces java auth ESS min wx.navigateToMiniProgram({ appId: ‘xxxxxxxxxxxxxxxxxx‘, // 要跳轉的小程序的appid path: ‘page/
Android 從網頁中跳轉到APP,從微信開啟自己的app並開啟指定頁面
先說實現步驟再說原理: 使用步驟 一,首先要給你要開啟的應用中的activity設定過濾器(在清單檔案裡設定)以JumpActivity為例如下面的: <intent-filter> 中就是所需過濾器 <activity android:name=".
微信小程式--實現按鈕跳轉另一個頁面
首先建立一個按鈕 在 index.wxml頁面中建立一個容器作為按鈕 <view class='day-weather' bindtap='onTapDayWeather'> </
Android一個應用跳轉另外一個應用
APP1: Intent tIntent = new Intent(); ComponentName tComp = new ComponentName("com.example.newporject"(另外一個應用包名), "com.example.newpo
activity跳轉另一個activity時,當前activity銷燬的原因探究
在改寫別人demo的時候發現內部有一個progressdialog,然而在我刪除這個progressdialog後發現跳轉到下一個activity的時候當前activity會銷燬(其實是崩潰了),但是加上對progre
springmvc怎麼重定向,從一個controller跳到另一個controller
前言: 有作者寫出了部分方法,但沒有給出具體實踐,小白看後雲裡霧裡,我這裡做兩件事:1 給出具體程式碼 2 對已經有的方法給出補充。 參考:http://my.oschina.net/u/1866821/blog/509054?fromerr=gT7zS0oS 第一種情況,
android如何從一個應用跳轉到另一個頁面
眾所周知,在一個APP內部,從一個頁面跳轉到另外一個頁面是使用startactivity函式來實現的。 同樣的,對於應用之間的跳轉也是如此的。應用直接的跳轉分為三種情況,為了方便描述,我加上有兩個應用A和B,需求是要從A點選一個按鈕,可以跳轉到B,同時A要傳資料給B,B能夠
android實現從一個activity跳轉到另一個activity中
<pre name="code" class="java"> </pre><pre class="java" name="code"><span style="font-size:18px;">要實現從1個activity跳到
iOS 從一個APP跳轉到另一個APP,並帶引數跳到指定頁面
功能實現:A跳到B並開啟B中指定頁面 步驟: 1.首先建立兩個專案(專案A,專案B),在專案B中的info.plist檔案中新增URL Types,如下圖所示:其中URL idenifier是專案B的bundle id ,URL Schemes 中新增一個命令字首
【轉】從一個App跳轉到另一APP
應用場景: 百度地圖等 第三方支付 第三方分享登陸 下面先說幾個概念性東西: 1 URL :統一資源定位符(可以沒有路徑但是必須要有協議頭) 2 scheme: 協議頭,用來決定查詢資源的方式 3
從一個App跳轉到另一APP
應用場景: 百度地圖等 第三方支付 第三方分享登陸下面先說幾個概念性東西: 1 URL :統一資源定位符(可以沒有路徑但是必須要有協議頭) 2 scheme: 協議頭,用來決定查詢資源的方式 3 path:路徑預設
從一個scene跳轉到另一個scene的程式碼以及一些控制元件程式碼
cc.find('Canvas').runAction(cc.sequence(cc.fadeOut(1.0),cc.callFunc(function(){ cc.director.loadScene('WAR');}))) this.nod
從一個servlet跳轉到另一個webapp的某個地址處理請求
例如:使用者下單servlet跳轉至另一個應用倉庫管理的servlet中核對商品資訊,再確認後返回使用者請求。 <span style="font-size:14px;">public class test extends HttpServlet{ pri
Android 從一個應用跳轉到另外一個應用中的問題
有時候一個應用不可能做到盡善盡美,有很多功能我們可以藉助一些已經比較成熟的應用來實現 比如音樂視訊播放器 當需要的時候我們就可以跳轉到這些應用中 //獲取launcher中的應用列表 In
在一個Activity中結束另一個Activity的方法;如何是從A跳轉到B, 結束A的;關於Activity在後臺被銷燬的處理;關於Activity在後臺被銷燬的處理
型別一:在一個Activity中結束另一個Activity的方法 下面的以ActivityB 結束ActivityA 為例: 方法一: 1.首先在 ActivityA 中定義一個 Activity