Created
November 2, 2015 06:18
-
-
Save ckurtm/ea4ba85c1dfc7be4a43b to your computer and use it in GitHub Desktop.
Revisions
-
ckurtm created this gist
Nov 2, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.peirr.test"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <receiver android:name=".MyReceiver" android:enabled="true" android:exported="true" /> <service android:name=".MyService" android:enabled="true" android:exported="true" /> <activity android:name=".MyActivity" android:exported="true" /> </application> </manifest> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ package com.peirr.test; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MyActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); TextView lname = (TextView) findViewById(R.id.name); TextView lage = (TextView) findViewById(R.id.age); Intent intent = getIntent(); if (intent != null) { String name = intent.getStringExtra("name"); int age = intent.getIntExtra("age",0); lname.setText(name); lage.setText(String.valueOf(age)); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ package com.peirr.test; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class MyReceiver extends BroadcastReceiver { public MyReceiver() {} @Override public void onReceive(Context context, Intent intent) { if (intent != null) { String name = intent.getStringExtra("name"); int age = intent.getIntExtra("age",0); Toast.makeText(context,"MyReceiver Received: [name:"+name+"] [age:"+age+"]",Toast.LENGTH_SHORT).show(); } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ package com.peirr.test; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.widget.Toast; public class MyService extends Service { public MyService() {} @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. throw new UnsupportedOperationException("Not yet implemented"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { String name = intent.getStringExtra("name"); int age = intent.getIntExtra("age",0); Toast.makeText(this, "MyService Received: [name:" + name + "] [age:" + age + "]", Toast.LENGTH_SHORT).show(); } return super.onStartCommand(intent, flags, startId); } }